Skip to content

Commit e32a2e6

Browse files
committed
fix: throw error message from discord
1 parent 79c1c28 commit e32a2e6

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# midjourney-fetch
22
[![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)
33

4-
Fetch api for midjournery on discord
4+
Fetch api for midjourney on discord
55

66
## Usage
77
```typescript

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "midjourney-fetch",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"description": "",
55
"type": "module",
66
"main": "./dist/index.js",

src/midjourney.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,21 @@ export class Midjourney {
9090
},
9191
});
9292
if (res.status >= 400) {
93-
throw new Error(`[${res.status}]Interactions failed`);
93+
let msg = '';
94+
try {
95+
const data = await res.json();
96+
if (this.debugger) {
97+
this.log('Request failed', JSON.stringify(data));
98+
}
99+
msg = data?.message;
100+
} catch (e) {
101+
// catch JSON error
102+
}
103+
if (msg) {
104+
throw new Error(msg);
105+
} else {
106+
throw new Error(`Interactions failed with ${res.status}`);
107+
}
94108
}
95109
}
96110

0 commit comments

Comments
 (0)