mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-01 05:11:34 +02:00
Merge pull request #2985 from overleaf/msm-oerror-remove-unprocessable-entity-error
Replace UnprocessableEntityError with calls to unprocessableEntity() handler GitOrigin-RevId: 4bba389c8cdf87a40137d49db571fa81aaac4239
This commit is contained in:
@@ -1,5 +1,16 @@
|
||||
const logger = require('logger-sharelatex')
|
||||
|
||||
function renderJSONError(res, message, info) {
|
||||
const fullInfo = { message, ...info }
|
||||
if (info.message) {
|
||||
logger.warn(
|
||||
info,
|
||||
`http error info shouldn't contain a 'message' field, will be overridden`
|
||||
)
|
||||
}
|
||||
res.json(fullInfo)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
forbidden(req, res, message = 'restricted', info = {}) {
|
||||
res.status(403)
|
||||
@@ -7,16 +18,24 @@ module.exports = {
|
||||
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)
|
||||
return renderJSONError(res, message, info)
|
||||
default:
|
||||
return res.send('restricted')
|
||||
}
|
||||
},
|
||||
|
||||
unprocessableEntity(req, res, message = 'unprocessable entity', info = {}) {
|
||||
res.status(422)
|
||||
switch (req.accepts(['html', 'json'])) {
|
||||
case 'html':
|
||||
return res.render('general/400', {
|
||||
title: 'Client Error',
|
||||
message: message
|
||||
})
|
||||
case 'json':
|
||||
return renderJSONError(res, message, info)
|
||||
default:
|
||||
return res.send('unprocessable entity')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user