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

                          
 

                                                    
                                       
 


                                                                                                     

   



                                                                              
 
                                   
'use strict'

const util = require('util')

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

const reqValidatorsUtils = {
  checkErrors: checkErrors
}

function checkErrors (req, res, next, status_code) {
  if (status_code === undefined) status_code = 400
  const 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 = reqValidatorsUtils