From 6c6a6f9fc830305f139d991a1240724fecc7a5a5 Mon Sep 17 00:00:00 2001 From: lvqq Date: Sat, 20 May 2023 11:36:07 +0800 Subject: [PATCH] fix: throw correct message from discord --- package.json | 2 +- src/midjourney.ts | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 1006081..d1b8aa7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "midjourney-fetch", - "version": "0.1.3", + "version": "0.1.4", "description": "", "type": "module", "main": "./dist/index.js", diff --git a/src/midjourney.ts b/src/midjourney.ts index 1332bf7..b1b2ba2 100644 --- a/src/midjourney.ts +++ b/src/midjourney.ts @@ -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}`); } }