feat:Global Error Handlers #28#32
Open
abhayrajjais01 wants to merge 4 commits intoOSeMOSYS:masterfrom
Open
Conversation
|
Hey, I noticed there's a related PR (#33) introducing an api_response() helper to standardize response formatting across routes. Since the error handlers here currently construct the response dictionary manually, I was wondering if it might be worth considering using that helper once it lands. That could help keep success and error responses aligned from a single source of truth and avoid small format differences over time. Happy to hear what you think |
Author
|
"Thanks for the review, @arnchlmcodes , I completely agree that standardizing our responses is the way to go here i will pull in the changes from PR #33 and refactor these error handlers to use the api_response helper to ensure consistency |
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 #28 by implementing standardized global JSON error handlers for
404 Not Foundand500 Internal Server Errorin the Flask backend.Note: Since the codebase routes 404s to the frontend React app by default, special care was taken to only return JSON 404s for API-specific routes to avoid breaking the frontend router.
What was changed
@app.errorhandler(404)in API/app.py. It checks the request headers (Accept: application/json) and path (/api/) to determine if it should return a standardized JSON error message or fall back to the React index page.@app.errorhandler(Exception)that catches global server-side exceptions (500s) and returns a uniform JSON response. This was necessary to ensure the WSGI web server (waitress) propagates the formatted JSON error to the client instead of standard HTML debugging logs.Verification
/api/non-existent) and verified the correct JSON error response block was returned.index.html.Exceptionduring testing and verified the internal server error is caught and formatted properly as JSON.Fixes #28