From e030bfb59dd5ee65f20a64686ec9b22ca39f70ae Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 2 Jun 2021 18:15:41 +0200 Subject: Refactor server errors handler --- server/helpers/express-utils.ts | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) (limited to 'server/helpers/express-utils.ts') diff --git a/server/helpers/express-utils.ts b/server/helpers/express-utils.ts index 10a860787..010c6961a 100644 --- a/server/helpers/express-utils.ts +++ b/server/helpers/express-utils.ts @@ -8,7 +8,6 @@ import { isArray } from './custom-validators/misc' import { logger } from './logger' import { deleteFileAndCatch, generateRandomString } from './utils' import { getExtFromMimetype } from './video' -import { ProblemDocument, ProblemDocumentExtension } from 'http-problem-details' function buildNSFWFilter (res?: express.Response, paramNSFW?: string) { if (paramNSFW === 'true') return true @@ -126,34 +125,6 @@ function getCountVideos (req: express.Request) { return req.query.skipCount !== true } -// helpers added in server.ts and used in subsequent controllers used -const apiResponseHelpers = (req, res: express.Response, next = null) => { - res.fail = (options) => { - const { data, status = HttpStatusCode.BAD_REQUEST_400, message, title, type, docs = res.docs, instance } = options - - const extension = new ProblemDocumentExtension({ - ...data, - docs, - // fields for <= 3.2 compatibility, deprecated - error: message, - code: type - }) - - res.status(status) - res.setHeader('Content-Type', 'application/problem+json') - res.json(new ProblemDocument({ - status, - title, - instance, - // fields intended to replace 'error' and 'code' respectively - detail: message, - type: type && 'https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/' + type - }, extension)) - } - - if (next) next() -} - // --------------------------------------------------------------------------- export { @@ -163,6 +134,5 @@ export { badRequest, createReqFiles, cleanUpReqFiles, - getCountVideos, - apiResponseHelpers + getCountVideos } -- cgit v1.2.3