Repository navigation
feat: send error stacks in responses when NODE_ENV is development - #503
Open
officialasishkumar wants to merge 1 commit into
Open
officialasishkumar wants to merge 1 commit into
officialasishkumar wants to merge 1 commit into
Conversation
The README documents that error stacks are sent in responses when NODE_ENV is set to 'development'. micro 9.x implemented this in sendError(), but the TypeScript rewrite dropped the behaviour together with its tests, so in 10.x NODE_ENV has no effect on error responses. sendError() now sends `error.stack` as the response body when NODE_ENV is 'development', keeping the same status code as before (the error's statusCode, or 500). If the error has no stack, the usual body is sent. Outside of development, responses are unchanged: the error message for errors with a statusCode, and 'Internal Server Error' otherwise. NODE_ENV is read on each call so it can be changed at runtime and in tests. Tests cover the stack being sent in development with and without a statusCode, and the message/'Internal Server Error' body in production. Closes vercel#502
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.
Closes #502
The README says error stacks are sent in responses when
NODE_ENVisdevelopment. micro 9.x did that insendError(), but the TypeScript rewrite (#458) dropped it together withtest/development.js, so in 10.xNODE_ENVhas no effect on error responses.Changes
NODE_ENVisdevelopment,sendError()sendserror.stackas the body. The status code doesn't change: it'serror.statusCodeif set, otherwise 500.statusCodesenderror.message, and other errors sendInternal Server Error.NODE_ENVis read on each call rather than when the module loads, so tests can toggle it.How to test
NODE_ENV=development micro index.js curl localhost:3000 # Error: Custom\n at module.exports (...)New tests in
test/suite/index.tscover the stack in development, with and without astatusCode, and the unchanged bodies in production. Without the change, both development tests fail.pnpm test,type-checkandeslint-checkpass.