Refactor: Implement global error handling and clean up controllers (Fixes #447)#450
Open
Jivan-Patel wants to merge 2 commits into
Open
Refactor: Implement global error handling and clean up controllers (Fixes #447)#450Jivan-Patel wants to merge 2 commits into
Jivan-Patel wants to merge 2 commits into
Conversation
Contributor
|
@Jivan-Patel Please take a look on security issue by github ai |
Contributor
Author
|
@KaranUnique, The vulnerability flagged by the GitHub Advanced Security CodeQL has been resolved. So please review and merged my PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🐛 Description
This PR addresses issue #447 by introducing a global error-handling middleware to the Express application and refactoring all backend controllers to adhere to the DRY (Don't Repeat Yourself) principle.
Previously, every controller manually wrapped its logic in a
try/catchblock and returned a hardcoded500response. This resulted in duplicated code (35+ occurrences) and inconsistent error responses across the application.✅ Changes Made
middlewares/errorHandler.js: A global Express error-handling middleware that catches errors passed vianext(err)and sends a unified, consistent JSON response. It also securely handles stack traces by omitting them in production.server.js: Registered theerrorHandlermiddleware securely at the bottom of the middleware stack (right after the API routes).res.status(500)manual catch blocks withnext(error)in the following controllers:authController.jsaiController.jsquestionController.jsresumeController.jssessionController.jsuserSheetProgressController.jsachievementController.jsjobController.js🎯 Benefits
Fixes #447