From 41736196a9aac61a1e46e962996105e274fc90f9 Mon Sep 17 00:00:00 2001 From: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Wed, 16 Oct 2024 18:32:32 +0900 Subject: [PATCH] =?UTF-8?q?=E5=9E=8B=E3=81=A8=E3=81=97=E3=81=A6=E7=94=A8?= =?UTF-8?q?=E6=84=8F=E3=81=99=E3=82=8B=E3=81=A0=E3=81=91=E3=81=AB=E3=81=97?= =?UTF-8?q?=E3=81=A6=E3=81=8A=E3=81=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/misskey-js/src/api.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/misskey-js/src/api.ts b/packages/misskey-js/src/api.ts index 0b4a075450..ed1282957f 100644 --- a/packages/misskey-js/src/api.ts +++ b/packages/misskey-js/src/api.ts @@ -18,8 +18,8 @@ export type APIError = { info: Record; }; -export function isAPIError(reason: any) { - return reason instanceof Error && MK_API_ERROR in reason; +export function isAPIError(reason: Record): reason is APIError { + return reason[MK_API_ERROR] === true; } export type FetchLike = (input: string, init?: { @@ -117,11 +117,12 @@ export class APIClient { if (res.status === 200 || res.status === 204) { resolve(body); } else { - reject(new Error(body.error)); + reject({ + [MK_API_ERROR]: true, + ...body.error, + }); } - }).catch((reason) => { - reject(new Error(reason)); - }); + }).catch(reject); }); } }