This repository has been archived by the owner on Jan 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: return HTTP 500 on unhandled errors during SSR
Fix #133. Add regression tests.
- Loading branch information
1 parent
051a673
commit d488fe2
Showing
6 changed files
with
78 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
28 changes: 28 additions & 0 deletions
28
tap-snapshots/test-projects-errors-index.test.js-TAP.test.js
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,28 @@ | ||
/* IMPORTANT | ||
* This snapshot file is auto-generated, but designed for humans. | ||
* It should be checked into source control and tracked carefully. | ||
* Re-generate by setting TAP_SNAPSHOT=1 and running tests. | ||
* Make sure to inspect the output below. Do not ignore changes! | ||
*/ | ||
'use strict' | ||
exports[ | ||
`test/projects/errors/index.test.js TAP test/projects/errors server-side 404 > undefined 1` | ||
] = ` | ||
<!DOCTYPE html><html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui" /> | ||
<title data-ream-head="true"></title> | ||
<link rel="preload" href="/_ream/chunk-vendors.js" as="script"><link rel="preload" href="/_ream/client.js" as="script"><link rel="prefetch" href="/_ream/chunk--base-pages-error.js"><link rel="prefetch" href="/_ream/chunk--base-pages-index.js"> | ||
</head> | ||
<body> | ||
<div id="_ream" data-server-rendered="true"><div><h1>404: page not found</h1></div></div> | ||
<script>window.__REAM__={"initialData":{}}</script><script src="/_ream/chunk-vendors.js" defer></script><script src="/_ream/client.js" defer></script> | ||
</body> | ||
</html> | ||
` |
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,28 @@ | ||
const testProject = require('../../lib/testProject') | ||
|
||
testProject(__dirname, async (t, c) => { | ||
await t.test('server-side 404', async t => { | ||
const res = await c.axios.get('/not-found', { | ||
validateStatus: status => status === 404 | ||
}) | ||
t.matchSnapshot(res.data) | ||
}) | ||
|
||
await t.test('client-side 404', async t => { | ||
const page = await c.loadPage('/') | ||
await page.waitForXPath('//a[text()="Not Found"]').then(el => el.click()) | ||
await page | ||
.waitForSelector('#_ream') | ||
.then(el => page.evaluate(el => el.innerText, el)) | ||
.then(text => t.equal(text, '404: page not found')) | ||
}) | ||
|
||
await t.test('server-side unhandled error', async t => { | ||
const res = await c.axios.get('/error', { | ||
validateStatus: status => status === 500 | ||
}) | ||
t.equal(res.data, 'server error') | ||
}) | ||
|
||
// Don't test unhandled client-side error for now, as it's (ha-ha) not handled. | ||
}) |
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,12 @@ | ||
<template> | ||
<div>test</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
getInitialData ({ req }) { | ||
const type = req ? 'server' : 'client' | ||
throw new Error(`unhandled ${type}-side error`) | ||
} | ||
} | ||
</script> |
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 @@ | ||
<template> | ||
<div> | ||
<router-link to="/not-found">Not Found</router-link> | ||
<router-link to="/error">Error</router-link> | ||
</div> | ||
</template> |
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 @@ | ||
module.exports = { | ||
fsRoutes: true | ||
} |