-
Notifications
You must be signed in to change notification settings - Fork 28
Description
The current FitFinder backend (built using Node.js/Express with TypeScript) does not consistently handle errors across API routes. This leads to inconsistent responses (default HTML error pages, unstructured error messages), making it difficult for frontend clients to handle errors reliably and safely.
We should implement a global error handling middleware and standardized error response format, plus add request validation for all endpoints to catch malformed or invalid requests before they reach business logic.
Problem
The backend currently does not have centralized error handling or request validation. Inconsistent error responses and leaked stack traces make it difficult for frontend clients to handle errors and poses potential security risks.
Solution
Implement a global error handling middleware in Express and enforce standardized JSON error responses across all API routes. Add request validation to ensure API inputs are correct.
Acceptance Criteria
- Centralized error handler middleware added
- 404 handler for unknown routes
- Validation errors return structured messages
- Internal errors return safe generic message
- No stack traces exposed in API responses
Manual Testing
GET /unknown-route- Submit invalid body to existing route
- Force an exception inside route handler