-import { inspect } from 'util'
+import * as express from 'express'
+import { validationResult } from 'express-validator/check'
+import { logger } from '../../helpers/logger'
-import { logger } from '../../helpers'
+function areValidationErrors (req: express.Request, res: express.Response) {
+ const errors = validationResult(req)
-function checkErrors (req, res, next, statusCode?) {
- if (statusCode === undefined) statusCode = 400
- const errors = req.validationErrors()
+ if (!errors.isEmpty()) {
+ logger.warn('Incorrect request parameters', { path: req.originalUrl, err: errors.mapped() })
+ res.status(400).json({ errors: errors.mapped() })
- 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 true
}
- return next()
+ return false
}
// ---------------------------------------------------------------------------
export {
- checkErrors
+ areValidationErrors
}