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