diff options
Diffstat (limited to 'server/helpers/express-utils.ts')
-rw-r--r-- | server/helpers/express-utils.ts | 32 |
1 files changed, 1 insertions, 31 deletions
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' | |||
8 | import { logger } from './logger' | 8 | import { logger } from './logger' |
9 | import { deleteFileAndCatch, generateRandomString } from './utils' | 9 | import { deleteFileAndCatch, generateRandomString } from './utils' |
10 | import { getExtFromMimetype } from './video' | 10 | import { getExtFromMimetype } from './video' |
11 | import { ProblemDocument, ProblemDocumentExtension } from 'http-problem-details' | ||
12 | 11 | ||
13 | function buildNSFWFilter (res?: express.Response, paramNSFW?: string) { | 12 | function buildNSFWFilter (res?: express.Response, paramNSFW?: string) { |
14 | if (paramNSFW === 'true') return true | 13 | if (paramNSFW === 'true') return true |
@@ -126,34 +125,6 @@ function getCountVideos (req: express.Request) { | |||
126 | return req.query.skipCount !== true | 125 | return req.query.skipCount !== true |
127 | } | 126 | } |
128 | 127 | ||
129 | // helpers added in server.ts and used in subsequent controllers used | ||
130 | const apiResponseHelpers = (req, res: express.Response, next = null) => { | ||
131 | res.fail = (options) => { | ||
132 | const { data, status = HttpStatusCode.BAD_REQUEST_400, message, title, type, docs = res.docs, instance } = options | ||
133 | |||
134 | const extension = new ProblemDocumentExtension({ | ||
135 | ...data, | ||
136 | docs, | ||
137 | // fields for <= 3.2 compatibility, deprecated | ||
138 | error: message, | ||
139 | code: type | ||
140 | }) | ||
141 | |||
142 | res.status(status) | ||
143 | res.setHeader('Content-Type', 'application/problem+json') | ||
144 | res.json(new ProblemDocument({ | ||
145 | status, | ||
146 | title, | ||
147 | instance, | ||
148 | // fields intended to replace 'error' and 'code' respectively | ||
149 | detail: message, | ||
150 | type: type && 'https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/' + type | ||
151 | }, extension)) | ||
152 | } | ||
153 | |||
154 | if (next) next() | ||
155 | } | ||
156 | |||
157 | // --------------------------------------------------------------------------- | 128 | // --------------------------------------------------------------------------- |
158 | 129 | ||
159 | export { | 130 | export { |
@@ -163,6 +134,5 @@ export { | |||
163 | badRequest, | 134 | badRequest, |
164 | createReqFiles, | 135 | createReqFiles, |
165 | cleanUpReqFiles, | 136 | cleanUpReqFiles, |
166 | getCountVideos, | 137 | getCountVideos |
167 | apiResponseHelpers | ||
168 | } | 138 | } |