36 lines
859 B
TypeScript
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);
|
|
}
|
|
}
|