Skip to content

Instantly share code, notes, and snippets.

@arifsetyawan
Created August 28, 2022 09:02
Show Gist options
  • Save arifsetyawan/2fc6a229cb3f7900e269166a26e6777d to your computer and use it in GitHub Desktop.
Save arifsetyawan/2fc6a229cb3f7900e269166a26e6777d to your computer and use it in GitHub Desktop.
import { NextFunction, Request, Response } from "express";
import { validationResult } from "express-validator";
import { RequestValidationError } from "../errors/request-validation-error";
export const validateRequest = (
req: Request,
res: Response,
next: NextFunction
) => {
const errors = validationResult(req);
if (!errors.isEmpty()) {
throw new RequestValidationError(errors.array());
}
next();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment