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,
})
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,
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)
}