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.

break validation chain

See original GitHub issue

Hello, 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:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Igor-Lopescommented, Jan 11, 2019

Hi, any updates on this issue ?

0reactions
lock[bot]commented, May 31, 2019

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.

Read more comments on GitHub >

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

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