1
0
Fork 0
peertube/server/middlewares/validators/utils.ts
2017-10-19 09:43:01 +02:00

21 lines
586 B
TypeScript

import { validationResult } from 'express-validator/check'
import * as express from 'express'
import { logger } from '../../helpers'
function checkErrors (req: express.Request, res: express.Response, next: express.NextFunction) {
const errors = validationResult(req)
if (!errors.isEmpty()) {
logger.warn('Incorrect request parameters', { path: req.originalUrl, err: errors.mapped() })
return res.status(400).json({ errors: errors.mapped() })
}
return next()
}
// ---------------------------------------------------------------------------
export {
checkErrors
}