We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f52f744 commit 5457af8Copy full SHA for 5457af8
1 file changed
‎src/observability/middleware/handle-errors.ts‎
@@ -100,9 +100,13 @@ const handleError: ErrorRequestHandler = async function handleError(
100
101
// Special handling for when a middleware calls `next(404)`
102
if (error === 404) {
103
- // Note that if this fails, it will swallow that error.
104
- nextApp.render404(req, res)
105
- return
+ // Route to App Router for proper 404 handling
+ req.url = '/404'
+ 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)
110
}
111
if (typeof error === 'number') {
112
throw new Error("Don't use next(xxx) where xxx is any other number than 404")
0 commit comments