Repository navigation
fix(server): send sync route matching errors to the error handler - #146
Merged
Merged
Conversation
Without global middleware, a sync error raised while finding the route (for example, by a matcher cast) skipped the app error handler. The middleware runner does not catch a sync error from its final handler, so the error rejected the runner itself. The server logged it as fatal and the default error handler sent a 500. With global middleware, the same error reached the app error handler. The route finder now returns sync errors as a rejected promise, like it already does for E_ROUTE_NOT_FOUND.
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.
Note
AI assistance was used to draft parts of the implementation, tests, and PR description.
Hey! 👋🏻
Without global middleware, a sync error raised while matching the route did not reach the app error handler. For example, a matcher
castthat throws. The server logged it as fatal ("Exception raised by error handler") and the default error handler sent a 500. With global middleware, the same error reached the app error handler.The cause is in the middleware
Runner: it callsfinalHandler().catch(errorHandler), so a sync error from the final handler skips the.catchand rejects the runner itself. With global middleware, the route finder runs inside a middleware'snext(), so the error becomes a rejection of that middleware and the runner catches it.The route finder now returns sync errors as a rejected promise, as it already does for
E_ROUTE_NOT_FOUND.New test:
pass route matching errors to the error handler. It registers no global middleware and a route whosecastthrows, and expects the response from the app error handler. It fails on9.xwithexpected 422, got 500.