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.

.custom() not working with promise

See original GitHub issue

I am trying to get .custom() working from the check API but it appears that it’s not working?

Working (only showing essential information):

check.body('email').trim().isEmail().normalizeEmail().custom((_value) => {
    return true;
});

expressValidatorCheck.validationResult(req)..throw();

Not working (only showing essential information:

check.body('email').trim().isEmail().normalizeEmail().custom((_value) => {
    return Promise.resolve();
});

check.validationResult(req).throw();

The docs state: The custom validator may return a promise to indicate an async validation task. In case it’s rejected, the field is considered invalid. Therefore I would expect both examples to result in a “passed validation” however the second example always fails.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
gustavohenkecommented, Oct 5, 2017

Thanks for the report @jplusje.

The code currently expects all validators to unbox as a truthy value. This means even async validators that return promises should have a value, eg Promise.resolve(true) to be considered as passed.

1reaction
gustavohenkecommented, Oct 5, 2017

Yes, but as the docs say, a resolved promise should mean a passed validation, and this is not happening yet. Will fix it so this doesn’t happen to other users in the future.

Read more comments on GitHub >

github_iconTop Results From Across the Web

custom promise function not giving me any results
I imported a custom promise function from utils.js to scripts.js to use but I don't get any results back. utils.js
Read more >
Promise - JavaScript - MDN Web Docs
Returns a new Promise object that is rejected with the given reason. Returns a new Promise object that is resolved with the given...
Read more >
Error handling with promises - The Modern JavaScript Tutorial
The handler should analyze errors (custom error classes help) and rethrow unknown ones (maybe they are programming mistakes). It's ok not to use ......
Read more >
Learn JavaScript Promises by Building a Custom ...
Learn promises from scratch by implementing a custom promise. You will understand asynchronous JavaScript better ... Problems with callbacks.
Read more >
Guide to promises in Node.js - LogRocket Blog
How do promises work? Creating a custom promise; Consuming a promise; Chaining promises; Node.js promisfy() method; Promise vs.
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