Skip to content

fix(server): send sync route matching errors to the error handler - #146

Merged
thetutlage merged 1 commit into
9.xfrom
fix/sync-route-errors
Oct 15, 2026
Merged

thetutlage merged 1 commit into
9.xfrom
fix/sync-route-errors

Conversation

@RomainLanz

Copy link
Copy Markdown
Member

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 cast that 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 calls finalHandler().catch(errorHandler), so a sync error from the final handler skips the .catch and rejects the runner itself. With global middleware, the route finder runs inside a middleware's next(), 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 whose cast throws, and expects the response from the app error handler. It fails on 9.x with expected 422, got 500.

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.
@thetutlage
thetutlage merged commit c2feaa7 into 9.x Oct 15, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants