Skip to content

Commit

Permalink
fix: throw error message from discord
Browse files Browse the repository at this point in the history
  • Loading branch information
lvqq committed May 14, 2023
1 parent 79c1c28 commit e32a2e6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# midjourney-fetch
[![npm version](https://img.shields.io/npm/v/midjourney-fetch.svg)](https://www.npmjs.com/package/midjourney-fetch) ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/GPTGenius/midjourney-fetch/ci.yml?branch=main) ![node-current (scoped)](https://img.shields.io/node/v/midjourney-fetch) ![GitHub](https://img.shields.io/github/license/GPTGenius/midjourney-fetch)

Fetch api for midjournery on discord
Fetch api for midjourney on discord

## Usage
```typescript
Expand Down
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.1",
"version": "0.1.2",
"description": "",
"type": "module",
"main": "./dist/index.js",
Expand Down
16 changes: 15 additions & 1 deletion src/midjourney.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,21 @@ export class Midjourney {
},
});
if (res.status >= 400) {
throw new Error(`[${res.status}]Interactions failed`);
let msg = '';
try {
const data = await res.json();
if (this.debugger) {
this.log('Request failed', JSON.stringify(data));
}
msg = data?.message;
} catch (e) {
// catch JSON error
}
if (msg) {
throw new Error(msg);
} else {
throw new Error(`Interactions failed with ${res.status}`);
}
}
}

Expand Down

0 comments on commit e32a2e6

Please sign in to comment.