Merge branch 'develop' into feat-mijs-expose-error-types
This commit is contained in:
commit
0f077f7216
|
@ -264,9 +264,6 @@
|
|||
- Feat: `/drive/files/create` のリクエストに対応(`multipart/form-data`に対応)
|
||||
- Feat: `/admin/role/create` のロールポリシーの型を修正
|
||||
|
||||
### Misskey.js
|
||||
- Feat: reject時のエラーに型情報を追加
|
||||
|
||||
## 2024.5.0
|
||||
|
||||
### Note
|
||||
|
|
|
@ -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<string, any>;
|
||||
};
|
||||
|
||||
// @public (undocumented)
|
||||
type App = components['schemas']['App'];
|
||||
|
|
|
@ -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<string, any>;
|
||||
};
|
||||
|
||||
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));
|
||||
|
|
Loading…
Reference in New Issue