X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Ferror.ts;h=94762e35542bb779b6487d5d91f71d51151a6a2d;hb=0c302acb3c358b4d4d8dee45aed1de1108ea37ea;hp=7b116eb574d48f078ff84be1c707b4925cd04276;hpb=59b741d6e3bd883b0a32d7aa02f953cc1bee16d6;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/error.ts b/server/middlewares/error.ts index 7b116eb57..94762e355 100644 --- a/server/middlewares/error.ts +++ b/server/middlewares/error.ts @@ -5,7 +5,7 @@ import { HttpStatusCode } from '@shared/models' function apiFailMiddleware (req: express.Request, res: express.Response, next: express.NextFunction) { res.fail = options => { - const { status = HttpStatusCode.BAD_REQUEST_400, message, title, type, data, instance } = options + const { status = HttpStatusCode.BAD_REQUEST_400, message, title, type, data, instance, tags } = options const extension = new ProblemDocumentExtension({ ...data, @@ -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, @@ -28,11 +31,11 @@ function apiFailMiddleware (req: express.Request, res: express.Response, next: e detail: message, type: type - ? `https://docs.joinpeertube.org/api/rest-reference.html#section/Errors/${type}` + ? `https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/${type}` : undefined }, extension) - logger.debug('Bad HTTP request.', { json }) + logger.debug('Bad HTTP request.', { json, tags }) res.json(json) }