36 lines
832 B
TypeScript
36 lines
832 B
TypeScript
|
|
|
|
export class CustomError extends Error {
|
|
constructor(
|
|
public message: string,
|
|
public statusCode: number,
|
|
) {
|
|
super(message);
|
|
this.name = "CustomError";
|
|
}
|
|
|
|
static badRequest(message: string): CustomError {
|
|
return new CustomError(message, 400);
|
|
}
|
|
|
|
static unauthorized(message: string = "Unauthorized"): CustomError {
|
|
return new CustomError(message, 401);
|
|
}
|
|
|
|
static forbidden(message: string = "Forbidden"): CustomError {
|
|
return new CustomError(message, 403);
|
|
}
|
|
|
|
static notFound(message: string): CustomError {
|
|
return new CustomError(message, 404);
|
|
}
|
|
|
|
static conflict(message: string): CustomError {
|
|
return new CustomError(message, 409);
|
|
}
|
|
|
|
static internalServer(message: string = "Internal Server Error"): CustomError {
|
|
return new CustomError(message, 500);
|
|
}
|
|
}
|