-
Notifications
You must be signed in to change notification settings - Fork 838
Closed
Labels
type: featureIssues related to new features.Issues related to new features.
Description
I like this library but the API could be better. I'm talking about this:
validate(post).then(errors => { // errors is an array of validation errors
if (errors.length > 0) {
console.log("validation failed. errors: ", errors);
} else {
console.log("validation succeed");
}
});It would be better if the validate() reject promise on errors. To do that, this line should be replaced with:
const errors = executor.stripEmptyErrors(validationErrors);
return errors.length ? Promise.reject(errors) : Promise.resolve();Then we simply work with validate() in async&await:
try {
await validate(post);
console.log("validation succeed");
} catch (errors) {
console.log("validation failed. errors: ", errors);
}And if you don't want to handle the errors (like in routing-controllers), you can just simply do that and it will throw error on errors:
await validate(post);
await postRepository.persist(post);
...What do you think about this? It might be a breaking change, so you should publish this as a major version (to prevent auto update on npm install for older users) or we have to create a new name for the validate function with promise rejection behavior.
Metadata
Metadata
Assignees
Labels
type: featureIssues related to new features.Issues related to new features.