diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 17:30:46 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:43:01 +0100 |
commit | a2431b7dcbc72c05101dcdbe631ff84a823aeb51 (patch) | |
tree | 09278a822905622a70ff976a75e09d99bc45639a /server/middlewares/validators/utils.ts | |
parent | fcaf1e0aa84213a1b1f1b1a44a3276eae35ebe70 (diff) | |
download | PeerTube-a2431b7dcbc72c05101dcdbe631ff84a823aeb51.tar.gz PeerTube-a2431b7dcbc72c05101dcdbe631ff84a823aeb51.tar.zst PeerTube-a2431b7dcbc72c05101dcdbe631ff84a823aeb51.zip |
Refractor validators
Diffstat (limited to 'server/middlewares/validators/utils.ts')
-rw-r--r-- | server/middlewares/validators/utils.ts | 14 |
1 files changed, 1 insertions, 13 deletions
diff --git a/server/middlewares/validators/utils.ts b/server/middlewares/validators/utils.ts index 77a1a0d4b..ca80acf29 100644 --- a/server/middlewares/validators/utils.ts +++ b/server/middlewares/validators/utils.ts | |||
@@ -1,19 +1,8 @@ | |||
1 | import { validationResult } from 'express-validator/check' | ||
2 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { validationResult } from 'express-validator/check' | ||
3 | 3 | ||
4 | import { logger } from '../../helpers' | 4 | import { logger } from '../../helpers' |
5 | 5 | ||
6 | function checkErrors (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
7 | const errors = validationResult(req) | ||
8 | |||
9 | if (!errors.isEmpty()) { | ||
10 | logger.warn('Incorrect request parameters', { path: req.originalUrl, err: errors.mapped() }) | ||
11 | return res.status(400).json({ errors: errors.mapped() }) | ||
12 | } | ||
13 | |||
14 | return next() | ||
15 | } | ||
16 | |||
17 | function areValidationErrors (req: express.Request, res: express.Response) { | 6 | function areValidationErrors (req: express.Request, res: express.Response) { |
18 | const errors = validationResult(req) | 7 | const errors = validationResult(req) |
19 | 8 | ||
@@ -30,6 +19,5 @@ function areValidationErrors (req: express.Request, res: express.Response) { | |||
30 | // --------------------------------------------------------------------------- | 19 | // --------------------------------------------------------------------------- |
31 | 20 | ||
32 | export { | 21 | export { |
33 | checkErrors, | ||
34 | areValidationErrors | 22 | areValidationErrors |
35 | } | 23 | } |