From 848347f193ca43f098e77b321f6555bd4a143e62 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 14 Apr 2023 09:34:53 +0200 Subject: [PATCH] Prevent exception when headers are already sent --- server/middlewares/error.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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,