mirror of https://github.com/Chocobozzz/PeerTube
Fix ERR_HTTP_HEADERS_SENT crash
parent
69601b66fe
commit
ca8a00d0e7
|
@ -83,6 +83,8 @@ function handleObjectStorageFailure (res: express.Response, err: Error) {
|
||||||
return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
|
return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.error('Object storage failure', { err })
|
||||||
|
|
||||||
return res.fail({
|
return res.fail({
|
||||||
status: HttpStatusCode.INTERNAL_SERVER_ERROR_500,
|
status: HttpStatusCode.INTERNAL_SERVER_ERROR_500,
|
||||||
message: err.message,
|
message: err.message,
|
||||||
|
|
|
@ -17,11 +17,6 @@ function apiFailMiddleware (req: express.Request, res: express.Response, next: e
|
||||||
error: message
|
error: message
|
||||||
})
|
})
|
||||||
|
|
||||||
res.status(status)
|
|
||||||
|
|
||||||
if (!res.headersSent) {
|
|
||||||
res.setHeader('Content-Type', 'application/problem+json')
|
|
||||||
}
|
|
||||||
|
|
||||||
const json = new ProblemDocument({
|
const json = new ProblemDocument({
|
||||||
status,
|
status,
|
||||||
|
@ -37,6 +32,12 @@ function apiFailMiddleware (req: express.Request, res: express.Response, next: e
|
||||||
|
|
||||||
logger.debug('Bad HTTP request.', { json, tags })
|
logger.debug('Bad HTTP request.', { json, tags })
|
||||||
|
|
||||||
|
res.status(status)
|
||||||
|
|
||||||
|
// Cannot display a proper error to the client since headers are already sent
|
||||||
|
if (res.headersSent) return
|
||||||
|
|
||||||
|
res.setHeader('Content-Type', 'application/problem+json')
|
||||||
res.json(json)
|
res.json(json)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue