Skip to content

Commit cf09cfc

Browse files
committed
fix: error handling improved and fixed
1 parent 767ff83 commit cf09cfc

3 files changed

Lines changed: 8 additions & 11 deletions

File tree

src/methods/create.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ module.exports = async (files = [], options = {}) => {
5252
});
5353

5454
if (res.error)
55-
throw (console.error('There was a error creating your bin'), res.error);
55+
throw new Error(
56+
'There was a error creating your bin: ' + res.error.message,
57+
);
5658

5759
const Bin = await get(res.data.key);
5860
if (!Bin) throw new Error('There was a error getting your bin');

src/methods/get.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ module.exports = async (key, options = {}) => {
3131

3232
const binData = await fetch(`https://sourceb.in/api/bins/${key}`);
3333
if (binData.error)
34-
throw (
35-
(console.error('There was a error in fetching bin data'),
36-
binData.error)
34+
throw new Error(
35+
'There was a error in fetching bin data: ' + binData.error.message,
3736
);
3837

3938
if (options.fetchContent) {
@@ -46,12 +45,8 @@ module.exports = async (key, options = {}) => {
4645
);
4746

4847
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)
48+
throw new Error(
49+
`There was a error in fetching bin content for file ${i}: ${content.error.message}`,
5550
);
5651

5752
binData.data.files[i] = {

src/util/fetch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ module.exports = async (url, options = {}) => {
2020
},
2121
})
2222
.then((res) => ({ data: res.body }))
23-
.catch((res) => ({ error: res }));
23+
.catch((error) => ({ error }));
2424
};

0 commit comments

Comments
 (0)