Summary
API errors vary in shape and code across endpoints. Some return { error: { message } }, others throw generic Error objects, and the frontend ApiError expects { statusCode, message, path }. A standardized, documented error schema is needed so clients can reliably handle failures.
Priority
P2
Files to work on
backend/src/api/middleware/errorHandler.ts
backend/src/errors/ (standardize)
backend/src/api/routes/
backend/docs/API_REFERENCE.md
Requirements
- Define canonical error schema:
{ error: { code, message, details?, path, correlationId } }
- Standardize error codes across the API:
VALIDATION_ERROR (400), UNAUTHORIZED (401), FORBIDDEN (403)
NOT_FOUND (404), CONFLICT (409), RATE_LIMITED (429)
UPSTREAM_UNAVAILABLE (502), VENICE_UNAVAILABLE (503), STELLAR_UNAVAILABLE (503)
INTERNAL_ERROR (500)
- Ensure
errorHandler middleware maps all thrown errors to this schema
- Add
correlationId to every error response (from request tracing)
- Document all error codes in
docs/API_REFERENCE.md with examples
- Legacy error formats are aligned (audit all controllers for consistent errors)
Acceptance Criteria
Summary
API errors vary in shape and code across endpoints. Some return
{ error: { message } }, others throw genericErrorobjects, and the frontendApiErrorexpects{ statusCode, message, path }. A standardized, documented error schema is needed so clients can reliably handle failures.Priority
P2
Files to work on
Requirements
{ error: { code, message, details?, path, correlationId } }VALIDATION_ERROR(400),UNAUTHORIZED(401),FORBIDDEN(403)NOT_FOUND(404),CONFLICT(409),RATE_LIMITED(429)UPSTREAM_UNAVAILABLE(502),VENICE_UNAVAILABLE(503),STELLAR_UNAVAILABLE(503)INTERNAL_ERROR(500)errorHandlermiddleware maps all thrown errors to this schemacorrelationIdto every error response (from request tracing)docs/API_REFERENCE.mdwith examplesAcceptance Criteria
{ error: { code, message, path, correlationId } }errorHandlercatches thrown errors and maps them correctlyVALIDATION_ERRORreturned for zod validation failuresVENICE_UNAVAILABLEreturned when Venice circuit is opencorrelationIdpresent in all error responsesApiErrorparsing works with the new schemadocs/API_REFERENCE.mdlists all error codes with usage examples