You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
imagine
I want to validate any data, and show any message to user on error
so I must to do somethink like:
const result = prettyValidator.test(data);
if (!result) {
const errors = prettyValidator.getErrors(data);
procassErrors(errors); // in my case -> res.status(422).send(errors);
return;
}
go on...
so I must to go through this cycle twice on error. and my data can contains lot of fields.
well, i can do this:
const errors= prettyValidator.getErrors(data);
if (errors.length > 0) {
res.status(422).send(errors);
return;
}
go on...
these performance is better, but the syntax is not semantic - looks like I expect an error.
and the result is not semantic - I expect an empty array on success
I recommend you to generate the errorArray in the test method too, but return true on success and throw errorArray on error.
this will allow to use try/catch and write more clean code
The text was updated successfully, but these errors were encountered:
imagine
I want to validate any data, and show any message to user on error
so I must to do somethink like:
so I must to go through this cycle twice on error. and my data can contains lot of fields.
well, i can do this:
these performance is better, but the syntax is not semantic - looks like I expect an error.
and the result is not semantic - I expect an empty array on success
I recommend you to generate the errorArray in the test method too, but return true on success and throw errorArray on error.
this will allow to use try/catch and write more clean code
The text was updated successfully, but these errors were encountered: