]>
Commit | Line | Data |
---|---|---|
b60e5f38 | 1 | import { validationResult } from 'express-validator/check' |
69818c93 | 2 | import * as express from 'express' |
34ca3b52 | 3 | |
65fcc311 | 4 | import { logger } from '../../helpers' |
c45f7f84 | 5 | |
8a02bd04 | 6 | function checkErrors (req: express.Request, res: express.Response, next: express.NextFunction) { |
b60e5f38 | 7 | const errors = validationResult(req) |
34ca3b52 | 8 | |
b60e5f38 C |
9 | if (!errors.isEmpty()) { |
10 | logger.warn('Incorrect request parameters', { path: req.originalUrl, err: errors.mapped() }) | |
8a02bd04 | 11 | return res.status(400).json({ errors: errors.mapped() }) |
34ca3b52 C |
12 | } |
13 | ||
9f10b292 C |
14 | return next() |
15 | } | |
16 | ||
17 | // --------------------------------------------------------------------------- | |
c45f7f84 | 18 | |
65fcc311 C |
19 | export { |
20 | checkErrors | |
21 | } |