Subd/server/error/api-error.handler.ts
2024-04-23 12:08:46 +04:00

21 lines
484 B
TypeScript

export class ApiErrorHandler extends Error {
status: number;
constructor(status: number, message: string) {
super();
this.status = status;
this.message = message;
}
static notFound(message: string) {
return new ApiErrorHandler(404, message);
}
static internal(message: string) {
return new ApiErrorHandler(500, `Ошибка сервера: ${message}`);
}
static forbidden(message: string) {
return new ApiErrorHandler(403, message);
}
}