Skip to content

Keep 4xx status when there is no /_error page in App Router-only builds - #101188

Open
Mahdi-Hasan wants to merge 3 commits into
vercel:canaryfrom
Mahdi-Hasan:fix/101064-app-router-4xx-status
Open

Mahdi-Hasan wants to merge 3 commits into
vercel:canaryfrom
Mahdi-Hasan:fix/101064-app-router-4xx-status

Conversation

@Mahdi-Hasan

@Mahdi-Hasan Mahdi-Hasan commented Nov 5, 2026 •

Copy link
Copy Markdown

What?

In an App Router-only app (no pages/ directory), client errors that Next.js generates itself come back as 500 in production.

Request Before After
GET /items/%E0%A4 (malformed param) 500 400
POST /hello.txt (public file) 500 405
Range: bytes=500-600 on a 6-byte public file 500 416
If-Match: "nope" on a public file 500 412

Route handlers that return a 4xx themselves were already fine. 404 was also fine, because it has /_not-found.

Why?

renderErrorToResponseImpl in base-server.ts looks for a page to render for the status code. STATIC_STATUS_PAGES only contains /500, so every other code falls back to /_error. App Router-only builds have no /_error, so it throws missing required error components. The catch block then sets res.statusCode = 500.

That error is a WrappedBuildError, which is not logged. So the server output shows nothing.

How?

When no error page is found and the status is 4xx, return the standard status text (Bad Request, Method Not Allowed, ...) as text/plain and keep the status. 5xx still goes through the existing path.

Added test/e2e/app-dir/app-router-client-error-status. It covers 400, 405, 412, 416, a route handler returning 403, and a normal 200.

The new test passes locally in start and dev mode (webpack). Without the change in base-server.ts, the four 4xx cases fail with Received: 500 and the two control cases still pass.

If you'd rather render a built-in App Router page for these codes, I'm happy to change the approach.

Fixes #101064

Without a pages directory there is no `/_error` page, and only `/500` has
a built-in status page. Client errors such as 400, 405, 412 and 416 fell
through to "missing required error components" and were turned into 500.
Return a plain-text body and keep the original 4xx status instead.

Fixes vercel#101064

<!-- NEXT_JS_LLM -->
@Mahdi-Hasan
Mahdi-Hasan force-pushed the fix/101064-app-router-4xx-status branch from 52c34b6 to 1d558e4 Compare November 5, 2026 08:22
`statusCode` is `number | undefined` on the base response type.

<!-- NEXT_JS_LLM -->
@Mahdi-Hasan
Mahdi-Hasan marked this pull request as ready for review November 5, 2026 08:37

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

App Router-only production builds replace framework-generated 4xx responses with 500 when /_error is absent

1 participant