Created
August 28, 2022 08:57
-
-
Save arifsetyawan/5275542c60c7d49c36a80a89628c2508 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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