Problem
Error handling across the backend is inconsistent:
- Some routes throw generic
Error objects
- Others return
res.status(500).json({ error: 'message' }) directly
- The error handler in
backend/src/api/middleware/errorHandler.ts only handles known error shapes
- No distinction between client errors (4xx) and server errors (5xx)
Current State
Looking at error handling in routes and coordinator:
// Some places:
throw new Error('Task not found');
// Others:
return res.status(500).json({ error: 'Internal error' });
// Error handler assumes:
if (err instanceof AppError) { ... }
Proposed Solution
- Create
backend/src/errors/ directory with:
AppError.ts — base class with statusCode, isOperational, code
ValidationError.ts — 400 with field details
NotFoundError.ts — 404 with resource type/id
UnauthorizedError.ts — 401/403
RateLimitError.ts — 429
- Update error handler to recognize all custom error types
- Add
error.code for machine-readable error identification
- Ensure all errors are operational (no stack traces in production responses)
Acceptance Criteria
Difficulty
High — touches every route and middleware
Labels
backend enhancement complex
Problem
Error handling across the backend is inconsistent:
Errorobjectsres.status(500).json({ error: 'message' })directlybackend/src/api/middleware/errorHandler.tsonly handles known error shapesCurrent State
Looking at error handling in routes and coordinator:
Proposed Solution
backend/src/errors/directory with:AppError.ts— base class withstatusCode,isOperational,codeValidationError.ts— 400 with field detailsNotFoundError.ts— 404 with resource type/idUnauthorizedError.ts— 401/403RateLimitError.ts— 429error.codefor machine-readable error identificationAcceptance Criteria
backend/src/errors/Errorobjects thrown in routes{ error: { code, message, details? } }Difficulty
High — touches every route and middleware
Labels
backendenhancementcomplex