break validation chain
See original GitHub issueHello, I saw #235 but in order to make it more streamline maybe a breakOnError(message?: string)
or another chain function to break chain if last stage already resulted in an error might help.
Use case would be:
check('id').exists().withMessage('id cannot be null').isMongoId().breakOnError('id must be a valid ObjectId').custom(checkDB).withMessage('id not found').custom(checkLimit).withMessage('limit reached');
Above case would be
- check if ‘id’ exists in payload and is a mongoId, if not stop execution
- check if ‘id’ is exists in DB(custom) and check if limit has been reached(custom)
So it would be an alternative withMessage
function that breaks the validation chain if an error occurred.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
break validation chain on first error · Issue #638 - GitHub
Hi @ItsGosho, that's because different chains don't know about the errors generated by other chains, they are isolated.
Read more >express-validator Break validator chain - node.js
The fix for this has finally landed in v3.0.0! req.getValidationResult().then( result => { var errors = result.useFirstErrorOnly().array(); // enjoy an ...
Read more >Validation Chain API - express-validator
Stops running validations if any of the previous ones have failed. Useful to prevent a custom validator that touches a database or external...
Read more >Validator Chains - Laminas Documentation
By setting $breakChainOnFailure to true , if the validator fails, it will short-circuit execution of the chain, preventing subsequent validators from executing.
Read more >Validation using the Chain of Responsibility Pattern
The first step is to break the validator down into individual validators, each responsible for a single implementation of IVehicleModel. We'll ...
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
Hi, any updates on this issue ?
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.