aboutsummaryrefslogtreecommitdiffhomepage
path: root/middlewares/reqValidators/utils.js
blob: 5bc9f4f0b72c7492ab58678fb6cd3cbda549b805 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
;(function () {
  'use strict'

  var util = require('util')
  var logger = require('../../helpers/logger')

  var utils = {}

  utils.checkErrors = function (req, res, next, status_code) {
    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()
  }

  module.exports = utils
})()