Skip to content

2.3: Standardized API Error Handling #26

@steilerDev

Description

@steilerDev

User Story

As a developer, I want a standardized error handling mechanism for all API endpoints, so that clients receive consistent, machine-readable error responses regardless of which endpoint they call.

Parent Epic

EPIC-02: Application Shell & Infrastructure (#2)

Priority

Must Have

Dependencies

None

Acceptance Criteria

  • 1. All API error responses follow the standard shape: { "error": { "code": "MACHINE_READABLE_CODE", "message": "Human-readable", "details": {} } }
  • 2. A Fastify error handler plugin catches all thrown errors and formats them into the standard shape
  • 3. Validation errors (from Fastify schema validation) return 400 with VALIDATION_ERROR code and include field-level details
  • 4. Unhandled errors return 500 with INTERNAL_ERROR code and do NOT leak stack traces or internal details in production
  • 5. Standard error codes exist for: NOT_FOUND (404), UNAUTHORIZED (401), FORBIDDEN (403), CONFLICT (409), VALIDATION_ERROR (400)
  • 6. A helper function or class is available for routes to throw typed errors (e.g., throw new AppError('NOT_FOUND', 'Work item not found'))
  • 7. Error responses include the correct HTTP status code

Notes

  • The error shape is defined in CLAUDE.md under API Conventions
  • This is a cross-cutting concern that all downstream feature epics rely on for consistent API behavior
  • The error codes and HTTP status mapping should be defined in the shared package for reuse by the API client (Story 2.6)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions