2015-11-07 07:16:26 -06:00
|
|
|
;(function () {
|
|
|
|
'use strict'
|
|
|
|
|
|
|
|
var util = require('util')
|
2016-01-31 04:23:52 -06:00
|
|
|
|
2016-01-30 10:05:22 -06:00
|
|
|
var logger = require('../../helpers/logger')
|
2015-11-07 07:16:26 -06:00
|
|
|
|
2016-01-31 04:23:52 -06:00
|
|
|
var reqValidatorsUtils = {
|
|
|
|
checkErrors: checkErrors
|
|
|
|
}
|
2015-11-07 07:16:26 -06:00
|
|
|
|
2016-01-31 04:23:52 -06:00
|
|
|
function checkErrors (req, res, next, status_code) {
|
2015-11-07 07:16:26 -06:00
|
|
|
if (status_code === undefined) status_code = 400
|
|
|
|
var errors = req.validationErrors()
|
|
|
|
|
|
|
|
if (errors) {
|
|
|
|
logger.warn('Incorrect request parameters', { path: req.originalUrl, err: errors })
|
|
|
|
return res.status(status_code).send('There have been validation errors: ' + util.inspect(errors))
|
|
|
|
}
|
|
|
|
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
|
2016-01-31 04:23:52 -06:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
module.exports = reqValidatorsUtils
|
2015-11-07 07:16:26 -06:00
|
|
|
})()
|