sharkey/packages/backend/src/server/api/error.ts

34 lines
927 B
TypeScript
Raw Normal View History

/*
* SPDX-FileCopyrightText: syuilo and other misskey contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/
type E = { message: string, code: string, id: string, kind?: 'client' | 'server' | 'permission', httpStatusCode?: number };
export class ApiError extends Error {
public message: string;
public code: string;
public id: string;
public kind: string;
public httpStatusCode?: number;
public info?: any;
2022-09-18 03:27:08 +09:00
constructor(err?: E | null | undefined, info?: any | null | undefined) {
if (err == null) err = {
message: 'Internal error occurred. Please contact us if the error persists.',
code: 'INTERNAL_ERROR',
id: '5d37dbcb-891e-41ca-a3d6-e690c97775ac',
kind: 'server',
2021-12-09 23:58:30 +09:00
httpStatusCode: 500,
};
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;
this.info = info;
}
}