Skip to content

Commit

Permalink
fix: throw correct message from discord
Browse files Browse the repository at this point in the history
  • Loading branch information
lvqq committed May 20, 2023
1 parent bbd9786 commit 6c6a6f9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "midjourney-fetch",
"version": "0.1.3",
"version": "0.1.4",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand Down
7 changes: 3 additions & 4 deletions src/midjourney.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,17 @@ export class Midjourney {
},
});
if (res.status >= 400) {
let message = '';
try {
const data = await res.json();
if (this.debugger) {
this.log('Interactions failed', JSON.stringify(data));
}
if (data?.message) {
throw new Error(data.message);
}
message = data?.message;
} catch (e) {
// catch JSON error
}
throw new Error(`Interactions failed with ${res.status}`);
throw new Error(message || `Interactions failed with ${res.status}`);
}
}

Expand Down

0 comments on commit 6c6a6f9

Please sign in to comment.