aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/utils.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-09-15 12:17:08 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-09-15 12:17:08 +0200
commitb60e5f38daf77e720a27aa86d3b482c58906a03a (patch)
treea70909860ab9705d348b3c082f8af440e0a5e4d2 /server/middlewares/validators/utils.ts
parent315cc0cc1871ab2a6d6c1bb61cf7b9f10511c3a9 (diff)
downloadPeerTube-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.ts11
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 @@
1import 'express-validator' 1import { validationResult } from 'express-validator/check'
2import * as express from 'express' 2import * as express from 'express'
3import { inspect } from 'util'
4 3
5import { logger } from '../../helpers' 4import { logger } from '../../helpers'
6 5
7function checkErrors (req: express.Request, res: express.Response, next: express.NextFunction, statusCode = 400) { 6function 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()