mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Fix SSR error handling in the global scope (#3877)
* Fix SSR error handling. * Remove unwanted console.logs * Fix a typo. * Fix current tests. * Add a new test case for this case. * Error should only be logged if it is not a 404
This commit is contained in:
parent
206470283e
commit
77c8677e58
|
@ -55,9 +55,17 @@ export function getPagePath (page, {dir, dist}) {
|
|||
|
||||
export default function requirePage (page, {dir, dist}) {
|
||||
const pagePath = getPagePath(page, {dir, dist})
|
||||
|
||||
try {
|
||||
return require(pagePath)
|
||||
} catch (err) {
|
||||
if (err.code === 'MODULE_NOT_FOUND') {
|
||||
throw pageNotFoundError(page)
|
||||
}
|
||||
console.error(err)
|
||||
// If this is not a MODULE_NOT_FOUND error,
|
||||
// it should be something with the content of the page.
|
||||
// So, Next.js rendering system will catch it and process.
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
aa = 10 //eslint-disable-line
|
||||
|
||||
export default () => (
|
||||
<div>Hello</div>
|
||||
)
|
|
@ -96,11 +96,16 @@ export default function ({ app }, suiteName, render, fetch) {
|
|||
expect(pre.text()).toMatch(/The default export is not a React Component/)
|
||||
})
|
||||
|
||||
test('error', async () => {
|
||||
const $ = await get$('/error')
|
||||
test('error-inside-page', async () => {
|
||||
const $ = await get$('/error-inside-page')
|
||||
expect($('pre').text()).toMatch(/This is an expected error/)
|
||||
})
|
||||
|
||||
test('error-in-the-global-scope', async () => {
|
||||
const $ = await get$('/error-in-the-global-scope')
|
||||
expect($('pre').text()).toMatch(/aa is not defined/)
|
||||
})
|
||||
|
||||
test('asPath', async () => {
|
||||
const $ = await get$('/nav/as-path', { aa: 10 })
|
||||
expect($('.as-path-content').text()).toBe('/nav/as-path?aa=10')
|
||||
|
|
Loading…
Reference in a new issue