From 3866ea02d4a5c8e4c69a5d8633a883e3733414b9 Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Tue, 1 Jun 2021 16:07:58 +0200 Subject: correct error codes and backward compat --- server/helpers/express-utils.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'server/helpers') diff --git a/server/helpers/express-utils.ts b/server/helpers/express-utils.ts index bca59a83c..10a860787 100644 --- a/server/helpers/express-utils.ts +++ b/server/helpers/express-utils.ts @@ -129,15 +129,14 @@ function getCountVideos (req: express.Request) { // 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, message, title, type, docs, instance } = { - data: null, - ...options, - status: options.status || HttpStatusCode.BAD_REQUEST_400 - } + const { data, status = HttpStatusCode.BAD_REQUEST_400, message, title, type, docs = res.docs, instance } = options const extension = new ProblemDocumentExtension({ ...data, - docs: docs || res.docs + docs, + // fields for <= 3.2 compatibility, deprecated + error: message, + code: type }) res.status(status) @@ -146,12 +145,13 @@ const apiResponseHelpers = (req, res: express.Response, next = null) => { status, title, instance, - type: type && '' + type, - detail: message + // 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 !== null) next() + if (next) next() } // --------------------------------------------------------------------------- -- cgit v1.2.3