Customize validator returns library internal error
See original GitHub issueReproduction:
package.json
{
"name": "w",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"body-parser": "^1.18.3",
"express": "^4.16.3",
"express-validator": "^5.2.0"
}
}
app.json
const {body, validationResult} = require('express-validator/check')
require('express')()
.use(require('body-parser').json())
.use(
body('pwd').isLength({min: 8}, (pwd, {req}) => 'length must >= 8'),
body('pwdCfrm').custom((pwdCfrm, {req}) => {
if (pwdCfrm !== req.body.pwd)
throw new Error('pwds do not match')
}),
(req, res) => res.end(JSON.stringify(validationResult(req).array()))
).listen(8000, () => console.log('app is listening'))
result when opening ‘localhost:8000’ in browser
[{"location":"body","param":"pwd","msg":"Invalid value"},{"location":"body","param":"pwdCfrm","msg":"Cannot read property 'then' of undefined"}]
while expected result is only 'length must >= 8'
error
I also tried some workaround but thing does not work at all
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Display custom validator error with mat-error - Stack Overflow
The single line of code in this method is quite simple; it returns true (error exists) if the parent control (our FormGroup) is...
Read more >Error Handler does not return an expected response ... - GitHub
Issue Description The built-in error handler should handle validation error by the library validator as mentioned in the docs Checklist ...
Read more >Angular Custom Form Validators: Complete Guide
As we can see, the ValidationErrors object that we returned as the output of our custom validator was added to the pasword field...
Read more >Angular custom validators + trick for flexible custom validator
Here we are validating if the input can be converted to a date and if not, we return an error object with “invalidDate”...
Read more >Custom Validators - Vuelidate
A simple, but powerful, lightweight model-based validation for Vue.js 3 and 2.
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
I think always wrapping returned result by
Promise.resolve()
should work.This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.