aboutsummaryrefslogblamecommitdiffhomepage
path: root/server/middlewares/validators/utils.js
blob: f6e5b2b38206973cc9d2b26db940f4483f1ca0d1 (plain) (tree)
1
2
3
4
5
6
7
8
9
            
 
                            
 
                                              
 
                         

                          
 

                                                   
                                       
 

                                                                                       
                                                                                                    

   



                                                                              
 
                                
'use strict'

const util = require('util')

const logger = require('../../helpers/logger')

const validatorsUtils = {
  checkErrors: checkErrors
}

function checkErrors (req, res, next, statusCode) {
  if (statusCode === undefined) statusCode = 400
  const errors = req.validationErrors()

  if (errors) {
    logger.warn('Incorrect request parameters', { path: req.originalUrl, err: errors })
    return res.status(statusCode).send('There have been validation errors: ' + util.inspect(errors))
  }

  return next()
}

// ---------------------------------------------------------------------------

module.exports = validatorsUtils