@@ -11,7 +11,12 @@ import type { ParsedUrlQuery } from 'querystring'
11
11
import type { RenderOpts , RenderOptsPartial } from './render'
12
12
import type { ResponseCacheEntry , ResponseCacheValue } from './response-cache'
13
13
import type { UrlWithParsedQuery } from 'url'
14
- import type { CacheFs } from '../shared/lib/utils'
14
+ import {
15
+ CacheFs ,
16
+ NormalizeError ,
17
+ DecodeError ,
18
+ normalizeRepeatedSlashes ,
19
+ } from '../shared/lib/utils'
15
20
import type { PreviewData } from 'next/types'
16
21
import type { PagesManifest } from '../build/webpack/plugins/pages-manifest-plugin'
17
22
import type { BaseNextRequest , BaseNextResponse } from './base-http'
@@ -39,7 +44,6 @@ import {
39
44
checkIsManualRevalidate ,
40
45
} from './api-utils'
41
46
import * as envConfig from '../shared/lib/runtime-config'
42
- import { DecodeError , normalizeRepeatedSlashes } from '../shared/lib/utils'
43
47
import { isTargetLikeServerless } from './utils'
44
48
import Router from './router'
45
49
import { getPathMatch } from '../shared/lib/router/utils/path-match'
@@ -564,7 +568,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
564
568
] )
565
569
}
566
570
} catch ( err ) {
567
- if ( err instanceof DecodeError ) {
571
+ if ( err instanceof DecodeError || err instanceof NormalizeError ) {
568
572
res . statusCode = 400
569
573
return this . renderError ( null , req , res , '/_error' , { } )
570
574
}
@@ -612,7 +616,8 @@ export default abstract class Server<ServerOptions extends Options = Options> {
612
616
} catch ( err : any ) {
613
617
if (
614
618
( err && typeof err === 'object' && err . code === 'ERR_INVALID_URL' ) ||
615
- err instanceof DecodeError
619
+ err instanceof DecodeError ||
620
+ err instanceof NormalizeError
616
621
) {
617
622
res . statusCode = 400
618
623
return this . renderError ( null , req , res , '/_error' , { } )
@@ -985,7 +990,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
985
990
return
986
991
}
987
992
} catch ( err ) {
988
- if ( err instanceof DecodeError ) {
993
+ if ( err instanceof DecodeError || err instanceof NormalizeError ) {
989
994
res . statusCode = 400
990
995
return this . renderError ( null , req , res , '/_error' , { } )
991
996
}
@@ -1745,7 +1750,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
1745
1750
if ( err instanceof NoFallbackError && bubbleNoFallback ) {
1746
1751
throw err
1747
1752
}
1748
- if ( err instanceof DecodeError ) {
1753
+ if ( err instanceof DecodeError || err instanceof NormalizeError ) {
1749
1754
res . statusCode = 400
1750
1755
return await this . renderErrorToResponse ( ctx , err )
1751
1756
}
0 commit comments