Keep the client-error status when the error page cannot be rendered - #98103
Open
dennytosp wants to merge 3 commits into
Open
Keep the client-error status when the error page cannot be rendered#98103dennytosp wants to merge 3 commits into
dennytosp wants to merge 3 commits into
Conversation
The server sets a 4xx before trying to render an error page for it: 400 for a pathname that fails to decode, 405 for a disallowed method on a static asset. When no matching error page exists — an app-router-only app with a catch-all route, for instance — that render fails and the fallback used to overwrite the status with 500, so malformed requests and stray OPTIONS probes were reported as server errors. Preserve the original 4xx and respond with a matching plain-text body.
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.
Fixes #94278, #92527, #92141 — one shared root cause.
/%A0,/50%%) responds 500instead of 400.
OPTIONS/POSTon a static asset (/_next/static/chunks/*.js)responds 500 instead of 405.
page (
/400,/405). An app-router-only app with a catch-all route has no such page,so that render fails and the fallback branch hardcodes
res.statusCode = 500.req.urlis still the malformed URL during the re-render, so the secondrender throws the same error. For static assets the 405 guard at
router-server.ts:653runs correctly, but the status is overwritten afterwards by the fallback.
reason phrase matching the status.
packages/next/src/server/base-server.ts(+43/-2)fix(router-server): return 400 instead of 500 for malformed URLs when… #94283 patches
router-server.ts, but tracing shows that code path is never reached.test/production/app-dir/client-error-status-fallback), passing onboth turbopack and webpack.
middleware-general,500-page,custom-error-500,custom-error,404-page-custom-error,error-handler-not-found-req-url,pages-dir/production,file-serving).