Skip to content

Instantly share code, notes, and snippets.

@arifsetyawan
Created August 28, 2022 08:57
Show Gist options
  • Save arifsetyawan/5275542c60c7d49c36a80a89628c2508 to your computer and use it in GitHub Desktop.
Save arifsetyawan/5275542c60c7d49c36a80a89628c2508 to your computer and use it in GitHub Desktop.
import { ValidationError } from "express-validator";
import { CustomError } from "./custom-error";
export class RequestValidationError extends CustomError {
statusCode = 400;
constructor(public errors: ValidationError[]) {
super('error validating request');
Object.setPrototypeOf(this, RequestValidationError.prototype);
}
serializeError() {
return this.errors.map(error => {
return { message: error.msg, field: error.param };
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment