diff options
Diffstat (limited to 'middlewares/reqValidators/utils.js')
-rw-r--r-- | middlewares/reqValidators/utils.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/middlewares/reqValidators/utils.js b/middlewares/reqValidators/utils.js new file mode 100644 index 000000000..91ead27a5 --- /dev/null +++ b/middlewares/reqValidators/utils.js | |||
@@ -0,0 +1,22 @@ | |||
1 | ;(function () { | ||
2 | 'use strict' | ||
3 | |||
4 | var util = require('util') | ||
5 | var logger = require('../../src/logger') | ||
6 | |||
7 | var utils = {} | ||
8 | |||
9 | utils.checkErrors = function (req, res, next, status_code) { | ||
10 | if (status_code === undefined) status_code = 400 | ||
11 | var errors = req.validationErrors() | ||
12 | |||
13 | if (errors) { | ||
14 | logger.warn('Incorrect request parameters', { path: req.originalUrl, err: errors }) | ||
15 | return res.status(status_code).send('There have been validation errors: ' + util.inspect(errors)) | ||
16 | } | ||
17 | |||
18 | return next() | ||
19 | } | ||
20 | |||
21 | module.exports = utils | ||
22 | })() | ||