mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 09:09:36 +02:00
[web] do not send a second response from api error handler (#33526)
GitOrigin-RevId: 6974f5d5f7042d5170eb2a755715b2d139f06130
This commit is contained in:
@@ -128,31 +128,32 @@ async function handleError(error, req, res, next) {
|
||||
}
|
||||
|
||||
function handleApiError(err, req, res, next) {
|
||||
const shouldSendErrorResponse = !res.headersSent
|
||||
req.logger.addFields({ err })
|
||||
if (
|
||||
err instanceof Errors.NotFoundError ||
|
||||
err instanceof InvalidParamsError
|
||||
) {
|
||||
req.logger.setLevel('warn')
|
||||
res.sendStatus(404)
|
||||
if (shouldSendErrorResponse) res.sendStatus(404)
|
||||
} else if (
|
||||
err instanceof URIError &&
|
||||
err.message.match(/^Failed to decode param/)
|
||||
) {
|
||||
req.logger.setLevel('warn')
|
||||
res.sendStatus(400)
|
||||
if (shouldSendErrorResponse) res.sendStatus(400)
|
||||
} else if (err instanceof Errors.TooManyRequestsError) {
|
||||
req.logger.setLevel('warn')
|
||||
res.sendStatus(429)
|
||||
if (shouldSendErrorResponse) res.sendStatus(429)
|
||||
} else if (err instanceof Errors.ForbiddenError) {
|
||||
req.logger.setLevel('warn')
|
||||
res.sendStatus(403)
|
||||
if (shouldSendErrorResponse) res.sendStatus(403)
|
||||
} else if (err instanceof InvalidRequestError) {
|
||||
req.logger.setLevel('warn')
|
||||
res.sendStatus(400)
|
||||
if (shouldSendErrorResponse) res.sendStatus(400)
|
||||
} else {
|
||||
req.logger.setLevel('error')
|
||||
res.sendStatus(500)
|
||||
if (shouldSendErrorResponse) res.sendStatus(500)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user