Files
hackathon-opti-1a67c9077937…/backend/src/domain/errors/custom.error.ts
2026-05-23 12:24:52 -06:00

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);
}
}