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

                                  
                              
 
                                      
 
                                                                                                                  
                                       
 

                                                                                       
                                                                                               

   



                                                                              
 


             
import 'express-validator'
import * as express from 'express'
import { inspect } from 'util'

import { logger } from '../../helpers'

function checkErrors (req: express.Request, res: express.Response, next: express.NextFunction, 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: ' + inspect(errors))
  }

  return next()
}

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

export {
  checkErrors
}