Why getValidationResult doesn't reject the Promise when it has an error?
See original GitHub issueI can’t understand the purpose of doing:
req.getValidationResult.then((results) => {
if (!results.isEmpty()) {
// Error
}
});
Why this method exists (.isEmpty
)? Isn’t better to reject the promise, then I can get the error at the .catch
? .then
for me means that everything occurs okay.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Unable to pass custom express-validator check - Stack Overflow
The problem is when email does not exist, although it doesn't show Promise.reject , the code cannot process any further, validationResult(req) ...
Read more >Error handling with promises - The Modern JavaScript Tutorial
Consequent .catch is only able to handle a promise with state=rejected. A promise can have its state=rejected as a result of both sync...
Read more >Custom Error Messages - express-validator
If you're using a custom validator, then it may very well throw or reject promises to indicate an invalid value. In these cases,...
Read more >API Reference | Ajv JSON schema validator
This function has properties errors and schema . ... The returned promise will reject (and the callback will be called with an error)...
Read more >17.7.0 API Reference - joi.dev
a valid email address string; must have two domain parts e.g. example.com ... If validation fails, the promise rejects with the validation error....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Well, that’s my particular opinion. I’d like if we don’t need this verification statement. That’s very useful if we’re using async/await too.
A good name for a new method would be: ‘isValid’. So: ‘Is valid? Then do this’.
BTW, you could do something like the following, which will allow you to deal with the errors in the catch block of the promise: