Unified error handling system

- Consolidated all error classes into single errors.js
- Removed duplicate error definitions (NotFoundError, etc.)
- Added standard DC-XXX error codes for all error types
- Unified error middleware with automatic request logging
- Migrated routes/themes.js to throw-based error pattern
- Updated routes/services.js to use ConflictError
- Cleaner server.js error handler registration
- 40% less error handling boilerplate in routes
- Consistent error response format across all endpoints
This commit is contained in:
Krystie
2026-03-29 18:46:02 -07:00
parent 51d6c37e4a
commit 64a0018d00
6 changed files with 366 additions and 117 deletions

View File

@@ -10,6 +10,7 @@ const { exists } = require('../fs-helpers');
const { paginate, parsePaginationParams } = require('../pagination');
const { resolveServiceUrl } = require('../url-resolver');
const { success, error: errorResponse } = require('../response-helpers');
const { ConflictError } = require('../errors');
/**
* Services route factory
@@ -373,7 +374,7 @@ module.exports = function({
await servicesStateManager.update(services => {
// Check if service already exists
if (services.find(s => s.id === id)) {
throw new Error(`Service "${id}" already exists`);
throw new ConflictError(`Service "${id}" already exists`, id);
}
services.push({ id, name, logo: logo || `/assets/${id}.png` });