mirror of
https://github.com/comatory/fb2iCal
synced 2024-12-28 01:11:03 +01:00
37 lines
721 B
JavaScript
37 lines
721 B
JavaScript
const { checkValidURL } = require('./utils')
|
|
const MissingURLParameter = () => new Error('Please provide valid URL or event number.')
|
|
|
|
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() })
|
|
}
|
|
|
|
const checkURLParameter = (req, res, next) => {
|
|
const { url } = req.body
|
|
|
|
if (!url || !checkValidURL(url)) {
|
|
return next(MissingURLParameter())
|
|
}
|
|
|
|
return next()
|
|
}
|
|
|
|
module.exports = {
|
|
genericErrorHandler,
|
|
checkURLParameter,
|
|
}
|