Skip to content

Implement centralized error handling middleware #3

@landoyjx

Description

@landoyjx

Build a centralized error handler that catches all errors and returns consistent JSON responses with appropriate HTTP status codes (e.g., 400 for validation errors, 404 for missing resources, 500 for unexpected errors).

Acceptance Criteria:

  • All errors are returned as JSON objects with message and optionally code
  • Unhandled routes return 404 Not Found with JSON body
  • Validation errors return 400 Bad Request with JSON body

Test Cases:

  • Unit: Throwing a custom 404 error returns { "message": "..." } with status 404
  • Unit: Throwing a validation error returns { "message": "..." } with status 400
  • Edge: An unhandled exception returns 500 with a generic error message

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions