1 import * as express from 'express'
2 import { ProblemDocument, ProblemDocumentExtension } from 'http-problem-details'
3 import { HttpStatusCode } from '@shared/core-utils'
5 function apiFailMiddleware (req: express.Request, res: express.Response, next: express.NextFunction) {
6 res.fail = options => {
7 const { status = HttpStatusCode.BAD_REQUEST_400, message, title, type, data, instance } = options
9 const extension = new ProblemDocumentExtension({
12 docs: res.locals.docUrl,
15 // For <= 3.2 compatibility
20 res.setHeader('Content-Type', 'application/problem+json')
21 res.json(new ProblemDocument({
29 ? `https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/${type}`