File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -51,9 +51,10 @@ module.exports = async (files = [], options = {}) => {
5151 } ,
5252 } ) ;
5353
54- if ( ! res ) throw new Error ( 'There was a error creating your bin' ) ;
54+ if ( res . error )
55+ throw ( console . error ( 'There was a error creating your bin' ) , res . error ) ;
5556
56- const Bin = await get ( res . key ) ;
57+ const Bin = await get ( res . data . key ) ;
5758 if ( ! Bin ) throw new Error ( 'There was a error getting your bin' ) ;
5859
5960 return Bin ;
Original file line number Diff line number Diff line change @@ -30,30 +30,38 @@ 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 ) throw new Error ( 'There was a error in fetching bin data' ) ;
33+ if ( binData . error )
34+ throw (
35+ ( console . error ( 'There was a error in fetching bin data' ) ,
36+ binData . error )
37+ ) ;
3438
3539 if ( options . fetchContent ) {
36- for ( let i = 0 ; i < binData . files . length ; i ++ ) {
40+ for ( let i = 0 ; i < binData . data . files . length ; i ++ ) {
3741 const content = await fetch (
3842 `https://cdn.sourceb.in/bins/${ key } /${ i } ` ,
3943 {
4044 responseType : 'text' ,
4145 } ,
4246 ) ;
4347
44- if ( ! content )
45- throw new Error (
46- 'There was a error in fetching bin content for file ' + i ,
48+ if ( content . error )
49+ throw (
50+ ( console . error (
51+ 'There was a error in fetching bin content for file ' +
52+ i ,
53+ ) ,
54+ content . error )
4755 ) ;
4856
49- binData . files [ i ] = {
50- content,
51- ...binData . files [ i ] ,
57+ binData . data . files [ i ] = {
58+ content : content . data ,
59+ ...binData . data . files [ i ] ,
5260 } ;
5361 }
5462 }
5563
56- const Bin = new SourceBin ( key , binData ) ;
64+ const Bin = new SourceBin ( key , binData . data ) ;
5765
5866 return Bin ;
5967} ;
Original file line number Diff line number Diff line change @@ -19,6 +19,6 @@ module.exports = async (url, options = {}) => {
1919 'User-Agent' : `Sourcebin/${ version } https://www.npmjs.com/package/sourcebin` ,
2020 } ,
2121 } )
22- . then ( ( res ) => res . body )
23- . catch ( ( res ) => undefined ) ;
22+ . then ( ( res ) => ( { data : res . body } ) )
23+ . catch ( ( res ) => ( { error : res } ) ) ;
2424} ;
You can’t perform that action at this time.
0 commit comments