Skip to content

Commit 55687a5

Browse files
yekverAkryum
authored andcommitted
fix: Internal Server Error isn't shown if httpCode is 500, closes #55 (#56)
1 parent b83f211 commit 55687a5

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

docs/guide/configuration.md

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module.exports = {
2929
},
3030
// Paths
3131
distPath: path.resolve(__dirname, './dist'),
32+
error500Html: null,
3233
templatePath: path.resolve(__dirname, './dist/index.html'),
3334
serviceWorkerPath: path.resolve(__dirname, './dist/service-worker.js'),
3435
// Directives fallback

lib/app.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,23 @@ module.exports = (app, options) => {
106106
httpCode: 200,
107107
}
108108
renderer.renderToString(context, (err, html) => {
109-
if (err) {
109+
if (err || context.httpCode === 500) {
110110
console.error(`error during render url : ${req.url}`)
111-
console.error(err)
112111

113112
// Render Error Page
114113
let errorHtml = config.error500Html
115114
? fs.readFileSync(config.error500Html, 'utf-8')
116115
: '500 | Internal Server Error'
117116

118-
if (!isProd) {
119-
const errorMessage = `<pre>${err.stack}</pre>`
120-
config.error500Html
121-
? errorHtml = errorHtml.replace('<!--server-error-msg-->', errorMessage)
122-
: errorHtml += errorMessage
117+
if (err) {
118+
console.error(err)
119+
120+
if (!isProd) {
121+
const errorMessage = `<pre>${err.stack}</pre>`
122+
config.error500Html
123+
? errorHtml = errorHtml.replace('<!--server-error-msg-->', errorMessage)
124+
: errorHtml += errorMessage
125+
}
123126
}
124127

125128
res.status(500).send(errorHtml)

lib/config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ module.exports = {
66
entry: target => `./src/entry-${target}`,
77
defaultTitle: 'My app',
88
favicon: './public/favicon.ico',
9-
error500Html: null,
109
skipRequests: req => req.originalUrl === '/graphql',
1110
nodeExternalsWhitelist: [/\.css$/, /\?vue&type=style/],
1211
extendServer: null,
1312
// Paths
1413
distPath: null,
14+
error500Html: null,
1515
templatePath: null,
1616
serviceWorkerPath: null,
1717
directives: {},

0 commit comments

Comments
 (0)