Subd/server/error/api-error.handler.ts

21 lines
484 B
TypeScript
Raw Permalink Normal View History

2024-04-23 12:08:46 +04:00
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);
}
}