Files
overleaf-cep/services/web/app/src/Features/Errors/HttpErrorHandler.js
Miguel Serrano d8d3ac82e9 Replace HTTPErrors.ForbiddenError with calls to forbidden() handler (#2972)
GitOrigin-RevId: 2a0c8fdaef9ba62b97cebad84603e6f076d770c0
2020-07-11 02:04:21 +00:00

23 lines
618 B
JavaScript

const logger = require('logger-sharelatex')
module.exports = {
forbidden(req, res, message = 'restricted', info = {}) {
res.status(403)
switch (req.accepts(['html', 'json'])) {
case 'html':
return res.render('user/restricted', { title: 'restricted' })
case 'json':
const fullInfo = { message, ...info }
if (info.message) {
logger.warn(
info,
`http error info shouldn't contain a 'message' field, will be overridden`
)
}
return res.json(fullInfo)
default:
return res.send('restricted')
}
}
}