Merge branch 'develop' into feat-mijs-expose-error-types

This commit is contained in:
kakkokari-gtyih 2024-10-12 11:56:55 +09:00
commit 0f077f7216
3 changed files with 16 additions and 21 deletions

View File

@ -264,9 +264,6 @@
- Feat: `/drive/files/create` のリクエストに対応(`multipart/form-data`に対応) - Feat: `/drive/files/create` のリクエストに対応(`multipart/form-data`に対応)
- Feat: `/admin/role/create` のロールポリシーの型を修正 - Feat: `/admin/role/create` のロールポリシーの型を修正
### Misskey.js
- Feat: reject時のエラーに型情報を追加
## 2024.5.0 ## 2024.5.0
### Note ### Note

View File

@ -772,13 +772,13 @@ class APIClient {
} }
// @public (undocumented) // @public (undocumented)
class APIError extends Error { type APIError = {
// (undocumented) id: string;
readonly [MK_API_ERROR] = true; code: string;
constructor(response: any); message: string;
// (undocumented) kind: 'client' | 'server';
payload: any; info: Record<string, any>;
} };
// @public (undocumented) // @public (undocumented)
type App = components['schemas']['App']; type App = components['schemas']['App'];

View File

@ -9,16 +9,14 @@ export type {
const MK_API_ERROR = Symbol(); const MK_API_ERROR = Symbol();
export class APIError extends Error { export type APIError = {
id: string;
public payload; code: string;
public readonly [MK_API_ERROR] = true; message: string;
kind: 'client' | 'server';
constructor(response: any) { // eslint-disable-next-line @typescript-eslint/no-explicit-any
super('message' in response ? response.message : 'API Error'); info: Record<string, any>;
this.payload = response; };
}
}
export function isAPIError(reason: any) { export function isAPIError(reason: any) {
return reason instanceof Error && MK_API_ERROR in reason; return reason instanceof Error && MK_API_ERROR in reason;
@ -119,7 +117,7 @@ export class APIClient {
if (res.status === 200 || res.status === 204) { if (res.status === 200 || res.status === 204) {
resolve(body); resolve(body);
} else { } else {
reject(new APIError(body.error)); reject(new Error(body.error));
} }
}).catch((reason) => { }).catch((reason) => {
reject(new Error(reason)); reject(new Error(reason));