Files
source-gamepanel/apps/api/src/lib/errors.ts
T
2026-02-21 13:22:51 +03:00

31 lines
729 B
TypeScript

export class AppError extends Error {
constructor(
public statusCode: number,
message: string,
public code?: string,
) {
super(message);
this.name = 'AppError';
}
static badRequest(message: string, code?: string) {
return new AppError(400, message, code);
}
static unauthorized(message = 'Unauthorized', code?: string) {
return new AppError(401, message, code);
}
static forbidden(message = 'Forbidden', code?: string) {
return new AppError(403, message, code);
}
static notFound(message = 'Not found', code?: string) {
return new AppError(404, message, code);
}
static conflict(message: string, code?: string) {
return new AppError(409, message, code);
}
}