File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed
src/observability/middleware Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff 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" )
You can’t perform that action at this time.
0 commit comments