21 lines
484 B
TypeScript
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);
|
||
|
}
|
||
|
}
|