-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix(app renderer): set status code to 500 if unexpected error occurs …
…before streaming
- Loading branch information
Showing
8 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
test/production/app-dir/unexpected-error/app/isr-unexpected-error/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export const revalidate = 0 | ||
|
||
export default function UnexpectedErrorPage(props) { | ||
// use query param to only throw error during runtime, not build time | ||
if (props.searchParams.error) { | ||
throw new Error('Oh no') | ||
} | ||
return ( | ||
<> | ||
<p id="page">/unexpected-error</p> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function Root({ children }: { children: React.ReactNode }) { | ||
return ( | ||
<html> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
3 changes: 3 additions & 0 deletions
3
.../production/app-dir/unexpected-error/app/ssr-unexpected-error-after-streaming/loading.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Loading() { | ||
return <p>loading</p> | ||
} |
11 changes: 11 additions & 0 deletions
11
test/production/app-dir/unexpected-error/app/ssr-unexpected-error-after-streaming/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export default function UnexpectedErrorPage(props) { | ||
// use query param to only throw error during runtime, not build time | ||
if (props.searchParams.error) { | ||
throw new Error('Oh no') | ||
} | ||
return ( | ||
<> | ||
<p id="page">/unexpected-error</p> | ||
</> | ||
) | ||
} |
11 changes: 11 additions & 0 deletions
11
test/production/app-dir/unexpected-error/app/ssr-unexpected-error/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export default function UnexpectedErrorPage(props) { | ||
// use query param to only throw error during runtime, not build time | ||
if (props.searchParams.error) { | ||
throw new Error('Oh no') | ||
} | ||
return ( | ||
<> | ||
<p id="page">/unexpected-error</p> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* @type {import('next').NextConfig} | ||
*/ | ||
const nextConfig = {} | ||
|
||
module.exports = nextConfig |
26 changes: 26 additions & 0 deletions
26
test/production/app-dir/unexpected-error/unexpected-error.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { createNextDescribe } from 'e2e-utils' | ||
|
||
createNextDescribe( | ||
'unexpected-error', | ||
{ | ||
files: __dirname, | ||
}, | ||
({ next }) => { | ||
it('should set response status to 500 for unexpected errors in ssr app route', async () => { | ||
const res = await next.fetch('/ssr-unexpected-error?error=true') | ||
expect(res.status).toBe(500) | ||
}) | ||
|
||
it('cannot change response status when streaming has started', async () => { | ||
const res = await next.fetch( | ||
'/ssr-unexpected-error-after-streaming?error=true' | ||
) | ||
expect(res.status).toBe(200) | ||
}) | ||
|
||
it('should set response status to 500 for unexpected errors in isr app route', async () => { | ||
const res = await next.fetch('/isr-unexpected-error?error=true') | ||
expect(res.status).toBe(500) | ||
}) | ||
} | ||
) |