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
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:
messageand optionallycodeTest Cases: