mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-18 17:21:33 +00:00
fix: headers already sent errors
This commit is contained in:
parent
9dc52774be
commit
dd55d69612
@ -21,15 +21,13 @@ module.exports = (error, req, res, next) => {
|
||||
? error.statusCode
|
||||
: 500
|
||||
|
||||
res.status(statusCode)
|
||||
|
||||
const description = (isClientError || isServerError)
|
||||
? error.message
|
||||
: 'An unexpected error occurred. Try again?'
|
||||
|
||||
if (description) {
|
||||
return res.json({ success: false, description })
|
||||
return res.status(statusCode).json({ success: false, description })
|
||||
} else {
|
||||
return res.end()
|
||||
return res.status(statusCode).end()
|
||||
}
|
||||
}
|
||||
|
12
lolisafe.js
12
lolisafe.js
@ -254,14 +254,18 @@ safe.use('/api', api)
|
||||
|
||||
// Error pages
|
||||
safe.use((req, res, next) => {
|
||||
res.setHeader('Cache-Control', 'no-store')
|
||||
res.status(404).sendFile(path.join(paths.errorRoot, config.errorPages[404]))
|
||||
if (!res.headersSent) {
|
||||
res.setHeader('Cache-Control', 'no-store')
|
||||
res.status(404).sendFile(path.join(paths.errorRoot, config.errorPages[404]))
|
||||
}
|
||||
})
|
||||
|
||||
safe.use((error, req, res, next) => {
|
||||
logger.error(error)
|
||||
res.setHeader('Cache-Control', 'no-store')
|
||||
res.status(500).sendFile(path.join(paths.errorRoot, config.errorPages[500]))
|
||||
if (!res.headersSent) {
|
||||
res.setHeader('Cache-Control', 'no-store')
|
||||
res.status(500).sendFile(path.join(paths.errorRoot, config.errorPages[500]))
|
||||
}
|
||||
})
|
||||
|
||||
// Git hash
|
||||
|
Loading…
Reference in New Issue
Block a user