question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why getValidationResult doesn't reject the Promise when it has an error?

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rdsedmundocommented, May 7, 2017

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’.

1reaction
gustavohenkecommented, May 4, 2017

BTW, you could do something like the following, which will allow you to deal with the errors in the catch block of the promise:

req.getValidationResult().then( result => result.throw() ).then( () => {
  req.send( "success!" );
}, e => {
  req.status( 400 ).json( e.array() );
})
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found