Skip to content

Implement structured API error schema with consistent error codes and documentation #500

Description

@devJaja

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

  • Every API error response conforms to { error: { code, message, path, correlationId } }
  • Error code list is comprehensive and documented
  • errorHandler catches thrown errors and maps them correctly
  • VALIDATION_ERROR returned for zod validation failures
  • VENICE_UNAVAILABLE returned when Venice circuit is open
  • correlationId present in all error responses
  • Frontend ApiError parsing works with the new schema
  • docs/API_REFERENCE.md lists all error codes with usage examples

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions