aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/utils.ts
diff options
context:
space:
mode:
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()