Files
dashcaddy/dashcaddy-api/errors.js
Sami f61e85d9a7 Initial commit: DashCaddy v1.0
Full codebase including API server (32 modules + routes), dashboard frontend,
DashCA certificate distribution, installer script, and deployment skills.
2026-03-05 02:26:12 -08:00

49 lines
1.2 KiB
JavaScript

/**
* Typed Error Classes for DashCaddy API
* Provides structured errors that the global error handler catches automatically.
*/
class AppError extends Error {
constructor(message, statusCode = 500, code = 'INTERNAL_ERROR') {
super(message);
this.name = this.constructor.name;
this.statusCode = statusCode;
this.code = code;
}
}
class DockerError extends AppError {
constructor(message, details = {}) {
super(message, 500, 'DOCKER_ERROR');
this.details = details;
}
}
class CaddyError extends AppError {
constructor(message, details = {}) {
super(message, 502, 'CADDY_ERROR');
this.details = details;
}
}
class DNSError extends AppError {
constructor(message, details = {}) {
super(message, 502, 'DNS_ERROR');
this.details = details;
}
}
class AuthenticationError extends AppError {
constructor(message = 'Authentication required') {
super(message, 401, 'AUTH_REQUIRED');
}
}
class NotFoundError extends AppError {
constructor(resource = 'Resource') {
super(`${resource} not found`, 404, 'NOT_FOUND');
}
}
module.exports = { AppError, DockerError, CaddyError, DNSError, AuthenticationError, NotFoundError };