Skip to content

structured error taxonomy and centralized error middleware for routing #554

Description

@mikewheeleer

Summary

routing handlers format errors ad hoc, so clients get inconsistent shapes and status codes. Introduce a typed domain-error taxonomy and route everything through one error middleware.

Why this matters

Inconsistent errors are hard to consume and hide bugs. A typed taxonomy + one mapping point makes responses predictable and testable.

Requirements

  • Define a domain-error type with a code, HTTP status, and safe message.
  • Route all routing errors through a single error middleware producing { code, message, requestId }.
  • Never leak internal details or stack traces to clients.
  • Remove the per-handler ad-hoc error formatting.

Technical guidance

  • Map each domain error to exactly one status code in one place.
  • Preserve the requestId for correlation.

Edge cases — each must have a test

  • validation error -> consistent 400 shape
  • not-found -> 404 shape
  • conflict -> 409 shape
  • unexpected error -> 500 with no leakage
  • every error carries a requestId

Acceptance criteria

  • All requirements and every edge case above implemented and covered by tests
  • New unit and integration tests; existing tests still pass and no regressions
  • Structured, typed errors (no leaked internals; stable codes)
  • npm run lint, npm test, and npm run build all pass locally
  • Code follows the repo's existing conventions; no duplication or dead code
  • Short docs/comments explaining the design and any non-obvious decisions
  • PR description explains the approach and includes Closes #<issue>

Out of scope

  • Localized error messages
  • Client SDK error types

Rewards

Part of the GrantFox OSS / Official Campaign (FWC26) — this task may be rewarded. PR quality is assessed by AI: depth, correctness under edge cases, meaningful tests, and clean design are what earn the reward. Shallow changes (typos, formatting, trivial docs) do not qualify.

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions