Reputation: 1
I am using ajv-errors to customize error messages during input data validation. As the custom code for the "maxLength" keyword is repeated several times, I aim to override the default error message to something like "max_length_of_string_is_255_characters."
Unfortunately, I have not come across any documentation or examples addressing this specific matter. Has anyone attempted this and achieved success?
Upvotes: 0
Views: 35
Reputation: 6809
The Ajv errors are just plain JavaScript objects. You can write a function that goes through the errors and adjust them where needed, returning a new object with differing message, or grouping duplicate errors, etc.
function processAjvErrors(originalErrors: ErrorObject[]) : MyCustomErrorObject[] {
// ... adjust the errors to your needs
}
Upvotes: 0