File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ module.exports = async (files = [], options = {}) => {
2828 throw new SyntaxError ( 'Please give a array of files' ) ;
2929
3030 if ( files . length > 1 )
31- throw new Error (
31+ throw new CreateError (
3232 'Having multiple files in one bin is only for pro users, authentication is not currently supported via this wrapper' ,
3333 ) ;
3434
@@ -51,13 +51,17 @@ module.exports = async (files = [], options = {}) => {
5151 } ,
5252 } ) ;
5353
54- if ( res . error )
55- throw new Error (
56- 'There was a error creating your bin: ' + res . error . message ,
57- ) ;
54+ if ( res . error ) throw new CreateError ( res . error . message ) ;
5855
5956 const Bin = await get ( res . data . key ) ;
60- if ( ! Bin ) throw new Error ( 'There was a error getting your bin' ) ;
57+ if ( ! Bin ) throw new CreateError ( 'There was a error getting your bin' ) ;
6158
6259 return Bin ;
6360} ;
61+
62+ class CreateError extends Error {
63+ constructor ( message ) {
64+ super ( message ) ;
65+ this . name = 'CreateError' ;
66+ }
67+ }
Original file line number Diff line number Diff line change @@ -30,10 +30,7 @@ module.exports = async (key, options = {}) => {
3030 options = Object . assign ( defaultOptions , options ) ;
3131
3232 const binData = await fetch ( `https://sourceb.in/api/bins/${ key } ` ) ;
33- if ( binData . error )
34- throw new Error (
35- 'There was a error in fetching bin data: ' + binData . error . message ,
36- ) ;
33+ if ( binData . error ) throw new GetError ( binData . error . message ) ;
3734
3835 if ( options . fetchContent ) {
3936 for ( let i = 0 ; i < binData . data . files . length ; i ++ ) {
@@ -45,7 +42,7 @@ module.exports = async (key, options = {}) => {
4542 ) ;
4643
4744 if ( content . error )
48- throw new Error (
45+ throw new GetError (
4946 `There was a error in fetching bin content for file ${ i } : ${ content . error . message } ` ,
5047 ) ;
5148
@@ -60,3 +57,10 @@ module.exports = async (key, options = {}) => {
6057
6158 return Bin ;
6259} ;
60+
61+ class GetError extends Error {
62+ constructor ( message ) {
63+ super ( message ) ;
64+ this . name = 'GetError' ;
65+ }
66+ }
You can’t perform that action at this time.
0 commit comments