diff options
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() |