Repository navigation
feat: add stable error codes to errors thrown by Express - #6982
Open
gayanMatch wants to merge 4 commits into
Open
gayanMatch wants to merge 4 commits into
gayanMatch wants to merge 4 commits into
Conversation
Rename the 15 codes from ERR_* to EXPRESS_ERR_* so they do not collide with Node.js's own ERR_* namespace, and add a History.md entry listing every code and what throws it. Messages and error types are unchanged. Refs expressjs#6951
Returns true only for errors carrying one of the codes in express.errorCodes, so handlers can tell framework errors apart from application errors without a custom error class. Refs expressjs#6951
Member
|
If we want to wait for express@6 also is an option |
UlisesGascon
requested review from
Phillip9587,
bjohansebas,
blakeembrey,
jonchurch,
krzysdz and
wesleytodd
October 23, 2026 13:27
Member
|
@gayanMatch awesome work with this PR! I just pushed a72565c to include a prefix and 685d941 to include the |
Contributor
|
I have two questions after a quick look at the code:
By the way #6951 is tagged as 6.x and this PR as 5.x . Footnotes
|
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.
Errors thrown by Express now carry a stable
codeproperty so error handlers can branch on the code instead of matching message text. Implements the proposal in #6951. Original implementation by @gayanMatch.What's included
lib/errors.jswith one constant per error and factory helpers used at every throw siteexpress.errorCodes, a frozen object with all 15 codesexpress.isExpressError(err), true only for errors carrying one of these codesDecisions
EXPRESS_ERR_so they do not collide with Node.js'sERR_*namespaceinstanceof TypeErrorandRangeErrorchecks keep working, so this is semver-minorisExpressError()covers the "did Express throw this" question without changinginstanceofbehaviourFollow-ups
res.sendthrows for non-string bodies) and feat(res.redirect): add validation for url and status arguments #6404 (res.redirectvalidation) add new throw sites and will need codes once they landRefs #6951