diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-09-15 12:17:08 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-09-15 12:17:08 +0200 |
commit | b60e5f38daf77e720a27aa86d3b482c58906a03a (patch) | |
tree | a70909860ab9705d348b3c082f8af440e0a5e4d2 /server/middlewares/validators/utils.ts | |
parent | 315cc0cc1871ab2a6d6c1bb61cf7b9f10511c3a9 (diff) | |
download | PeerTube-b60e5f38daf77e720a27aa86d3b482c58906a03a.tar.gz PeerTube-b60e5f38daf77e720a27aa86d3b482c58906a03a.tar.zst PeerTube-b60e5f38daf77e720a27aa86d3b482c58906a03a.zip |
Upgrade express validator to v4
Diffstat (limited to 'server/middlewares/validators/utils.ts')
-rw-r--r-- | server/middlewares/validators/utils.ts | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/server/middlewares/validators/utils.ts b/server/middlewares/validators/utils.ts index 0424d5942..8845f8399 100644 --- a/server/middlewares/validators/utils.ts +++ b/server/middlewares/validators/utils.ts | |||
@@ -1,15 +1,14 @@ | |||
1 | import 'express-validator' | 1 | import { validationResult } from 'express-validator/check' |
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import { inspect } from 'util' | ||
4 | 3 | ||
5 | import { logger } from '../../helpers' | 4 | import { logger } from '../../helpers' |
6 | 5 | ||
7 | function checkErrors (req: express.Request, res: express.Response, next: express.NextFunction, statusCode = 400) { | 6 | function checkErrors (req: express.Request, res: express.Response, next: express.NextFunction, statusCode = 400) { |
8 | const errors = req.validationErrors() | 7 | const errors = validationResult(req) |
9 | 8 | ||
10 | if (errors) { | 9 | if (!errors.isEmpty()) { |
11 | logger.warn('Incorrect request parameters', { path: req.originalUrl, err: errors }) | 10 | logger.warn('Incorrect request parameters', { path: req.originalUrl, err: errors.mapped() }) |
12 | return res.status(statusCode).send('There have been validation errors: ' + inspect(errors)) | 11 | return res.status(statusCode).json({ errors: errors.mapped() }) |
13 | } | 12 | } |
14 | 13 | ||
15 | return next() | 14 | return next() |