Refactor the API to implement a centralized error handling middleware instead of handling errors individually inside each controller.
What Needs to Be Done:
Create a global error handling middleware (e.g., errorHandler.js).
Use Express error-handling pattern: next(error) inside controllers.
Remove repetitive try/catch response handling where possible.
Ensure all errors return a consistent structured response (e.g., status code, message).
Maintain existing functionality without breaking current routes.
The objective is to improve maintainability, enforce clean architecture principles, and standardize error responses across the entire API.
Refactor the API to implement a centralized error handling middleware instead of handling errors individually inside each controller.
What Needs to Be Done:
Create a global error handling middleware (e.g., errorHandler.js).
Use Express error-handling pattern: next(error) inside controllers.
Remove repetitive try/catch response handling where possible.
Ensure all errors return a consistent structured response (e.g., status code, message).
Maintain existing functionality without breaking current routes.
The objective is to improve maintainability, enforce clean architecture principles, and standardize error responses across the entire API.