Files
ScommettiApp/backend-node/shared/errors/index.js
T
2026-03-26 22:46:03 +01:00

56 lines
1.4 KiB
JavaScript

const AppError = require('./AppError');
const config = require('../../config');
class ValidationError extends AppError {
constructor(message, errors = null) {
super(message, config.HTTP_STATUS.BAD_REQUEST, true, errors);
this.name = 'ValidationError';
}
}
class NotFoundError extends AppError {
constructor(message = 'Resource not found') {
super(message, config.HTTP_STATUS.NOT_FOUND, true);
this.name = 'NotFoundError';
}
}
class ConflictError extends AppError {
constructor(message, errors = null) {
super(message, config.HTTP_STATUS.CONFLICT, true, errors);
this.name = 'ConflictError';
}
}
class UnauthorizedError extends AppError {
constructor(message = 'Unauthorized') {
super(message, config.HTTP_STATUS.UNAUTHORIZED, true);
this.name = 'UnauthorizedError';
}
}
class ForbiddenError extends AppError {
constructor(message = 'Forbidden') {
super(message, config.HTTP_STATUS.FORBIDDEN, true);
this.name = 'ForbiddenError';
}
}
class DatabaseError extends AppError {
constructor(message = 'Database operation failed', originalError = null) {
super(message, config.HTTP_STATUS.INTERNAL_SERVER_ERROR, false);
this.name = 'DatabaseError';
this.originalError = originalError;
}
}
module.exports = {
AppError,
ValidationError,
NotFoundError,
ConflictError,
UnauthorizedError,
ForbiddenError,
DatabaseError,
};