File tree 8 files changed +81
-0
lines changed
packages/next/src/server/app-render
test/production/app-dir/unexpected-error
ssr-unexpected-error-after-streaming
8 files changed +81
-0
lines changed Original file line number Diff line number Diff line change @@ -1616,6 +1616,10 @@ export const renderToHTMLOrFlight: AppPageRender = (
1616
1616
1617
1617
const is404 = res . statusCode === 404
1618
1618
1619
+ if ( ! is404 && ! hasRedirectError ) {
1620
+ res . statusCode = 500
1621
+ }
1622
+
1619
1623
// Preserve the existing RSC inline chunks from the page rendering.
1620
1624
// To avoid the same stream being operated twice, clone the origin stream for error rendering.
1621
1625
const serverErrorComponentsRenderOpts : typeof serverComponentsRenderOpts =
Original file line number Diff line number Diff line change
1
+ export const revalidate = 0
2
+
3
+ export default function UnexpectedErrorPage ( props ) {
4
+ // use query param to only throw error during runtime, not build time
5
+ if ( props . searchParams . error ) {
6
+ throw new Error ( 'Oh no' )
7
+ }
8
+ return (
9
+ < >
10
+ < p id = "page" > /unexpected-error</ p >
11
+ </ >
12
+ )
13
+ }
Original file line number Diff line number Diff line change
1
+ export default function Root ( { children } : { children : React . ReactNode } ) {
2
+ return (
3
+ < html >
4
+ < body > { children } </ body >
5
+ </ html >
6
+ )
7
+ }
Original file line number Diff line number Diff line change
1
+ export default function Loading ( ) {
2
+ return < p > loading</ p >
3
+ }
Original file line number Diff line number Diff line change
1
+ export default function UnexpectedErrorPage ( props ) {
2
+ // use query param to only throw error during runtime, not build time
3
+ if ( props . searchParams . error ) {
4
+ throw new Error ( 'Oh no' )
5
+ }
6
+ return (
7
+ < >
8
+ < p id = "page" > /unexpected-error</ p >
9
+ </ >
10
+ )
11
+ }
Original file line number Diff line number Diff line change
1
+ export default function UnexpectedErrorPage ( props ) {
2
+ // use query param to only throw error during runtime, not build time
3
+ if ( props . searchParams . error ) {
4
+ throw new Error ( 'Oh no' )
5
+ }
6
+ return (
7
+ < >
8
+ < p id = "page" > /unexpected-error</ p >
9
+ </ >
10
+ )
11
+ }
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @type {import('next').NextConfig }
3
+ */
4
+ const nextConfig = { }
5
+
6
+ module . exports = nextConfig
Original file line number Diff line number Diff line change
1
+ import { createNextDescribe } from 'e2e-utils'
2
+
3
+ createNextDescribe (
4
+ 'unexpected-error' ,
5
+ {
6
+ files : __dirname ,
7
+ } ,
8
+ ( { next } ) => {
9
+ it ( 'should set response status to 500 for unexpected errors in ssr app route' , async ( ) => {
10
+ const res = await next . fetch ( '/ssr-unexpected-error?error=true' )
11
+ expect ( res . status ) . toBe ( 500 )
12
+ } )
13
+
14
+ it ( 'cannot change response status when streaming has started' , async ( ) => {
15
+ const res = await next . fetch (
16
+ '/ssr-unexpected-error-after-streaming?error=true'
17
+ )
18
+ expect ( res . status ) . toBe ( 200 )
19
+ } )
20
+
21
+ it ( 'should set response status to 500 for unexpected errors in isr app route' , async ( ) => {
22
+ const res = await next . fetch ( '/isr-unexpected-error?error=true' )
23
+ expect ( res . status ) . toBe ( 500 )
24
+ } )
25
+ }
26
+ )
You can’t perform that action at this time.
0 commit comments