aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-09-01 09:27:57 +0200
committerChocobozzz <me@florianbigard.com>2023-09-01 09:27:57 +0200
commitca8a00d0e7cb71b77f8abc3a830810be9d50c9ad (patch)
tree658b9bd673dc10f9b6368d90893f60a3ae52b0e4 /server
parent69601b66feaeb6e508fffe5f7b4c31ccb8a79bb9 (diff)
downloadPeerTube-ca8a00d0e7cb71b77f8abc3a830810be9d50c9ad.tar.gz
PeerTube-ca8a00d0e7cb71b77f8abc3a830810be9d50c9ad.tar.zst
PeerTube-ca8a00d0e7cb71b77f8abc3a830810be9d50c9ad.zip
Fix ERR_HTTP_HEADERS_SENT crash
Diffstat (limited to 'server')
-rw-r--r--server/server/lib/object-storage/proxy.ts2
-rw-r--r--server/server/middlewares/error.ts11
2 files changed, 8 insertions, 5 deletions
diff --git a/server/server/lib/object-storage/proxy.ts b/server/server/lib/object-storage/proxy.ts
index bef899fed..af37029f8 100644
--- a/server/server/lib/object-storage/proxy.ts
+++ b/server/server/lib/object-storage/proxy.ts
@@ -83,6 +83,8 @@ function handleObjectStorageFailure (res: express.Response, err: Error) {
83 return res.sendStatus(HttpStatusCode.NOT_FOUND_404) 83 return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
84 } 84 }
85 85
86 logger.error('Object storage failure', { err })
87
86 return res.fail({ 88 return res.fail({
87 status: HttpStatusCode.INTERNAL_SERVER_ERROR_500, 89 status: HttpStatusCode.INTERNAL_SERVER_ERROR_500,
88 message: err.message, 90 message: err.message,
diff --git a/server/server/middlewares/error.ts b/server/server/middlewares/error.ts
index 706009795..51012af07 100644
--- a/server/server/middlewares/error.ts
+++ b/server/server/middlewares/error.ts
@@ -17,11 +17,6 @@ function apiFailMiddleware (req: express.Request, res: express.Response, next: e
17 error: message 17 error: message
18 }) 18 })
19 19
20 res.status(status)
21
22 if (!res.headersSent) {
23 res.setHeader('Content-Type', 'application/problem+json')
24 }
25 20
26 const json = new ProblemDocument({ 21 const json = new ProblemDocument({
27 status, 22 status,
@@ -37,6 +32,12 @@ function apiFailMiddleware (req: express.Request, res: express.Response, next: e
37 32
38 logger.debug('Bad HTTP request.', { json, tags }) 33 logger.debug('Bad HTTP request.', { json, tags })
39 34
35 res.status(status)
36
37 // Cannot display a proper error to the client since headers are already sent
38 if (res.headersSent) return
39
40 res.setHeader('Content-Type', 'application/problem+json')
40 res.json(json) 41 res.json(json)
41 } 42 }
42 43