narinder1231's picture
add middleware to handlevalidation errors
a1d9933
raw
history blame contribute delete
353 Bytes
import { validationResult } from 'express-validator';
import { Request, Response, NextFunction } from 'express';
export const handleValidationErrors = (req: Request, res: Response, next: NextFunction) => {
const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(400).json({ errors: errors.array() });
}
next();
};