]>
Commit | Line | Data |
---|---|---|
69818c93 C |
1 | import 'express-validator' |
2 | import * as express from 'express' | |
65fcc311 | 3 | import { inspect } from 'util' |
34ca3b52 | 4 | |
65fcc311 | 5 | import { logger } from '../../helpers' |
c45f7f84 | 6 | |
69818c93 | 7 | function checkErrors (req: express.Request, res: express.Response, next: express.NextFunction, statusCode = 400) { |
f0f5567b | 8 | const errors = req.validationErrors() |
34ca3b52 | 9 | |
9f10b292 C |
10 | if (errors) { |
11 | logger.warn('Incorrect request parameters', { path: req.originalUrl, err: errors }) | |
65fcc311 | 12 | return res.status(statusCode).send('There have been validation errors: ' + inspect(errors)) |
34ca3b52 C |
13 | } |
14 | ||
9f10b292 C |
15 | return next() |
16 | } | |
17 | ||
18 | // --------------------------------------------------------------------------- | |
c45f7f84 | 19 | |
65fcc311 C |
20 | export { |
21 | checkErrors | |
22 | } |