Skip to content

fix(serve): differentiate HTTP error codes instead of catch-all 500 #379

@fagemx

Description

@fagemx

Problem

All ledger/database errors in edda-serve become `AppError::Internal` → HTTP 500. There is no distinction between:

  • Transient errors (database locked, connection timeout) → should be 503
  • Data validation errors (missing field from ledger query) → could be 422
  • Not found via ledger (project doesn't exist) → should be 404

Current `AppError` has 5 variants (Validation/400, NotFound/404, Conflict/409, Unauthorized/401, Internal/500) but only Validation and Internal are used in most handlers. The other variants exist but are underutilized.

Scope

  1. Audit each handler's `?` propagation to identify where more specific status codes apply
  2. Add error classification at the handler level:
    • Ledger `open()` fails → 404 if project not found, 500 if I/O error
    • Query returns empty → 404 (not 500)
    • Database locked → 503 with Retry-After header
  3. Consider adding `AppError::ServiceUnavailable` variant for transient failures

Notes

  • `AppError` definition at `edda-serve/src/lib.rs:72`
  • `IntoResponse` impl at same file
  • This pairs well with the .context() work (GH-XXX) — better errors + better codes

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions