1
0
mirror of https://github.com/comatory/fb2iCal synced 2025-06-05 22:09:25 +02:00

add JSON response for errors when using JS

This commit is contained in:
Ondrej Synacek
2019-10-21 21:20:03 +02:00
parent 6a1ef614ad
commit 31a54b4ef7
3 changed files with 34 additions and 18 deletions

View File

@@ -1,7 +1,19 @@
const FBURLError = () => new Error('Not a valid Facebook URL!')
const sendJSON = (req) => {
return req.accepts().includes('application/json')
}
const genericErrorHandler = (err, req, res, next) => {
console.error(err.stack)
if (sendJSON(req)) {
res
.status(500)
.send({ error: err.toString() })
return
}
res
.status(500)
.render('error', { error: err.toString() })