Files
hackathon-opti-1a67c9077937…/backend/src/domain/errors/custom.error.ts
2026-05-22 19:26:38 -06:00

36 lines
859 B
TypeScript

/**
* custom.error.ts
* CustomError: clase base para errores personalizados.
* Facilita el manejo de errores en toda la aplicación.
*/
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 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);
}
}