2023-07-27 14:31:52 +09:00
|
|
|
/*
|
2024-02-14 00:59:27 +09:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 14:31:52 +09:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2023-03-09 14:27:16 +09:00
|
|
|
type E = { message: string, code: string, id: string, kind?: 'client' | 'server' | 'permission', httpStatusCode?: number };
|
2019-04-13 01:43:22 +09:00
|
|
|
|
2019-02-22 11:46:58 +09:00
|
|
|
export class ApiError extends Error {
|
|
|
|
public message: string;
|
|
|
|
public code: string;
|
|
|
|
public id: string;
|
|
|
|
public kind: string;
|
2019-02-23 11:20:58 +09:00
|
|
|
public httpStatusCode?: number;
|
2019-02-22 11:46:58 +09:00
|
|
|
public info?: any;
|
|
|
|
|
2022-09-18 03:27:08 +09:00
|
|
|
constructor(err?: E | null | undefined, info?: any | null | undefined) {
|
|
|
|
if (err == null) err = {
|
2019-02-22 11:46:58 +09:00
|
|
|
message: 'Internal error occurred. Please contact us if the error persists.',
|
|
|
|
code: 'INTERNAL_ERROR',
|
|
|
|
id: '5d37dbcb-891e-41ca-a3d6-e690c97775ac',
|
2019-02-23 11:20:58 +09:00
|
|
|
kind: 'server',
|
2021-12-09 23:58:30 +09:00
|
|
|
httpStatusCode: 500,
|
2019-02-22 11:46:58 +09:00
|
|
|
};
|
|
|
|
|
2022-09-18 03:27:08 +09:00
|
|
|
super(err.message);
|
|
|
|
this.message = err.message;
|
|
|
|
this.code = err.code;
|
|
|
|
this.id = err.id;
|
|
|
|
this.kind = err.kind ?? 'client';
|
|
|
|
this.httpStatusCode = err.httpStatusCode;
|
2019-02-22 11:46:58 +09:00
|
|
|
this.info = info;
|
|
|
|
}
|
|
|
|
}
|