Repository navigation
Return JSON errors without stack traces - #195
Open
NetworkTheoryAppliedResearchInstitute wants to merge 2 commits into
Open
NetworkTheoryAppliedResearchInstitute wants to merge 2 commits into
NetworkTheoryAppliedResearchInstitute wants to merge 2 commits into
Conversation
Express's default error handler answers with an HTML page that includes the stack trace and absolute file paths whenever NODE_ENV is not "production", and neither compose file sets it. Any request from an origin outside the CORS allow-list reached that handler as a 500. - Add middleware/errorHandler.js, registered after every route: always JSON, never the stack. 5xx responses carry only the status text and are logged server-side; 4xx responses show the message only when the error is marked safe to expose (as body-parser's are). - A refused CORS origin is now a 403 with a JSON message instead of a 500. - Tests cover the refused origin, a malformed JSON body, an unexpected throw and an unexposed 4xx. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Jodson Graves <info@ntari.org>
Resolve the backend/server.js conflict with #197 by taking main's server.js and reapplying this branch's three changes: require the JSON error handler, give the CORS refusal status 403 with an exposed message, and register the handler after every route. Full backend suite on the merge: node:test 64/64, Jest 65/65. Signed-off-by: Jodson Graves <info@ntari.org> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Express's default error handler answers with an HTML page that includes the stack trace and absolute file paths whenever
NODE_ENVis notproduction, and neither compose file sets it. A request from an origin outside the CORS allow-list reached that handler as a 500.Changes
backend/middleware/errorHandler.js, registered inserver.jsafter every route. It always answers in JSON and never includes the stack, whateverNODE_ENVis. 5xx responses carry only the status text and are logged server-side. 4xx responses show the message only when the error is marked safe to expose, as body-parser's are.backend/__tests__/errorHandler.test.jscovers the refused origin, a malformed JSON body, an unexpected throw and an unexposed 4xx.Tested on this branch:
npm testinbackend/passes, with 65/65 node:test (4 new) and 46/46 Jest. Agrinet's CI does not run the unit tests yet, so that run was local.Not changed: the compose files still leave
NODE_ENVunset. The handler makes that setting irrelevant to error output. No binding changes, so CONFORMANCE.md is untouched.🤖 Generated with Claude Code