diff --git a/CHANGELOG.md b/CHANGELOG.md index b355712d94..143b63f7b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -264,9 +264,6 @@ - Feat: `/drive/files/create` のリクエストに対応(`multipart/form-data`に対応) - Feat: `/admin/role/create` のロールポリシーの型を修正 -### Misskey.js -- Feat: reject時のエラーに型情報を追加 - ## 2024.5.0 ### Note diff --git a/packages/misskey-js/etc/misskey-js.api.md b/packages/misskey-js/etc/misskey-js.api.md index e6687e702f..21cf0f0f01 100644 --- a/packages/misskey-js/etc/misskey-js.api.md +++ b/packages/misskey-js/etc/misskey-js.api.md @@ -772,13 +772,13 @@ class APIClient { } // @public (undocumented) -class APIError extends Error { - // (undocumented) - readonly [MK_API_ERROR] = true; - constructor(response: any); - // (undocumented) - payload: any; -} +type APIError = { + id: string; + code: string; + message: string; + kind: 'client' | 'server'; + info: Record; +}; // @public (undocumented) type App = components['schemas']['App']; diff --git a/packages/misskey-js/src/api.ts b/packages/misskey-js/src/api.ts index 69e16dc02b..0b4a075450 100644 --- a/packages/misskey-js/src/api.ts +++ b/packages/misskey-js/src/api.ts @@ -9,16 +9,14 @@ export type { const MK_API_ERROR = Symbol(); -export class APIError extends Error { - - public payload; - public readonly [MK_API_ERROR] = true; - - constructor(response: any) { - super('message' in response ? response.message : 'API Error'); - this.payload = response; - } -} +export type APIError = { + id: string; + code: string; + message: string; + kind: 'client' | 'server'; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + info: Record; +}; export function isAPIError(reason: any) { return reason instanceof Error && MK_API_ERROR in reason; @@ -119,7 +117,7 @@ export class APIClient { if (res.status === 200 || res.status === 204) { resolve(body); } else { - reject(new APIError(body.error)); + reject(new Error(body.error)); } }).catch((reason) => { reject(new Error(reason));