.custom() not working with promise
See original GitHub issueI 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:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top 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 >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
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.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.