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