Skip to content

Commit 5457af8

Browse files
authored
🚀 Fix early-access 404 page to show proper Oops page 🎯 (#57462)
1 parent f52f744 commit 5457af8

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

‎src/observability/middleware/handle-errors.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,13 @@ const handleError: ErrorRequestHandler = async function handleError(
100100

101101
// Special handling for when a middleware calls `next(404)`
102102
if (error === 404) {
103-
// Note that if this fails, it will swallow that error.
104-
nextApp.render404(req, res)
105-
return
103+
// Route to App Router for proper 404 handling
104+
req.url = '/404'
105+
res.status(404)
106+
res.setHeader('x-pathname', req.path)
107+
res.locals = res.locals || {}
108+
res.locals.handledByAppRouter = true
109+
return nextApp.getRequestHandler()(req, res)
106110
}
107111
if (typeof error === 'number') {
108112
throw new Error("Don't use next(xxx) where xxx is any other number than 404")

0 commit comments

Comments
 (0)