From: Chocobozzz Date: Fri, 14 Apr 2023 07:34:53 +0000 (+0200) Subject: Prevent exception when headers are already sent X-Git-Tag: v5.2.0-rc.1~220 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=848347f193ca43f098e77b321f6555bd4a143e62;p=github%2FChocobozzz%2FPeerTube.git Prevent exception when headers are already sent --- diff --git a/server/middlewares/error.ts b/server/middlewares/error.ts index 7b116eb57..540edaeeb 100644 --- a/server/middlewares/error.ts +++ b/server/middlewares/error.ts @@ -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,