]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Prevent exception when headers are already sent
authorChocobozzz <me@florianbigard.com>
Fri, 14 Apr 2023 07:34:53 +0000 (09:34 +0200)
committerChocobozzz <me@florianbigard.com>
Fri, 14 Apr 2023 07:34:53 +0000 (09:34 +0200)
server/middlewares/error.ts

index 7b116eb574d48f078ff84be1c707b4925cd04276..540edaeeb063635c5ee6dbfcd3e5e69f0b5b6ad5 100644 (file)
@@ -18,7 +18,10 @@ function apiFailMiddleware (req: express.Request, res: express.Response, next: e
     })
 
     res.status(status)
-    res.setHeader('Content-Type', 'application/problem+json')
+
+    if (!res.headersSent) {
+      res.setHeader('Content-Type', 'application/problem+json')
+    }
 
     const json = new ProblemDocument({
       status,