errors.tsā¢1.22 kB
export class AppError extends Error {
constructor(
public readonly message: string,
public readonly statusCode: number = 500,
public readonly code: string = 'INTERNAL_ERROR',
public readonly details?: unknown,
) {
super(message);
this.name = this.constructor.name;
Error.captureStackTrace(this, this.constructor);
}
}
export class NotFoundError extends AppError {
constructor(message: string) {
super(message, 404, 'NOT_FOUND');
this.name = 'NotFoundError';
}
}
export class ValidationError extends AppError {
constructor(message: string, details?: unknown) {
super(message, 400, 'VALIDATION_ERROR', details);
this.name = 'ValidationError';
}
}
export class UnauthorizedError extends AppError {
constructor(message: string = 'Unauthorized') {
super(message, 401, 'UNAUTHORIZED');
this.name = 'UnauthorizedError';
}
}
export class ForbiddenError extends AppError {
constructor(message: string = 'Forbidden') {
super(message, 403, 'FORBIDDEN');
this.name = 'ForbiddenError';
}
}
export class ConflictError extends AppError {
constructor(message: string) {
super(message, 409, 'CONFLICT');
this.name = 'ConflictError';
}
}