aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/express-utils.ts
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2021-06-01 16:07:58 +0200
committerChocobozzz <chocobozzz@cpy.re>2021-06-02 16:57:07 +0200
commit3866ea02d4a5c8e4c69a5d8633a883e3733414b9 (patch)
treeac484fcf59a257ce526888a6b1d4cb8f61b4a49a /server/helpers/express-utils.ts
parent1cfbdd30d9913bfaa0c7e54f82e5b953646bb0d1 (diff)
downloadPeerTube-3866ea02d4a5c8e4c69a5d8633a883e3733414b9.tar.gz
PeerTube-3866ea02d4a5c8e4c69a5d8633a883e3733414b9.tar.zst
PeerTube-3866ea02d4a5c8e4c69a5d8633a883e3733414b9.zip
correct error codes and backward compat
Diffstat (limited to 'server/helpers/express-utils.ts')
-rw-r--r--server/helpers/express-utils.ts18
1 files changed, 9 insertions, 9 deletions
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) {
129// helpers added in server.ts and used in subsequent controllers used 129// helpers added in server.ts and used in subsequent controllers used
130const apiResponseHelpers = (req, res: express.Response, next = null) => { 130const apiResponseHelpers = (req, res: express.Response, next = null) => {
131 res.fail = (options) => { 131 res.fail = (options) => {
132 const { data, status, message, title, type, docs, instance } = { 132 const { data, status = HttpStatusCode.BAD_REQUEST_400, message, title, type, docs = res.docs, instance } = options
133 data: null,
134 ...options,
135 status: options.status || HttpStatusCode.BAD_REQUEST_400
136 }
137 133
138 const extension = new ProblemDocumentExtension({ 134 const extension = new ProblemDocumentExtension({
139 ...data, 135 ...data,
140 docs: docs || res.docs 136 docs,
137 // fields for <= 3.2 compatibility, deprecated
138 error: message,
139 code: type
141 }) 140 })
142 141
143 res.status(status) 142 res.status(status)
@@ -146,12 +145,13 @@ const apiResponseHelpers = (req, res: express.Response, next = null) => {
146 status, 145 status,
147 title, 146 title,
148 instance, 147 instance,
149 type: type && '' + type, 148 // fields intended to replace 'error' and 'code' respectively
150 detail: message 149 detail: message,
150 type: type && 'https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/' + type
151 }, extension)) 151 }, extension))
152 } 152 }
153 153
154 if (next !== null) next() 154 if (next) next()
155} 155}
156 156
157// --------------------------------------------------------------------------- 157// ---------------------------------------------------------------------------