Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Middleware fail fast #1100

Closed
NeverwinterMoon opened this issue Oct 12, 2021 · 6 comments · Fixed by #1214
Closed

Middleware fail fast #1100

NeverwinterMoon opened this issue Oct 12, 2021 · 6 comments · Fixed by #1214

Comments

@NeverwinterMoon
Copy link

NeverwinterMoon commented Oct 12, 2021

I managed to find a way to fail-fast the validation chain with bail, but what about failing fast the middleware list?

Say, I have

.post(
  '/somewhere',
  body('name').exists(),
  body('phoneNumber').exists(),
  handleStuff
)

If the name validation fails, I don't care to check phoneNumber anymore... Wasn't able to find a way to fail fast in this case. In the case above, if both validations fail, I will get errors for both of them.

@fedeci
Copy link
Member

fedeci commented Oct 12, 2021

Hi there, there is currently no way to accomplish what you are trying to.
This should be however fairly easy to implement directly in the check middleware or as a ValidationChain method (we need to bail early if the context contains errors) so I am marking this as a first good issue. We can discuss hereby about the implementation.

@kuldp18
Copy link

kuldp18 commented Mar 18, 2022

Hi @fedeci, I would like to work on this issue. Some guidance on how to solve this problem will be appreciated since I'm new to this type of stuff.

@Tariqu
Copy link

Tariqu commented Jan 5, 2023

I think we could throw the error and can prevent the calling next function or we can call the next with and error argument

@gustavohenke gustavohenke added this to the v7.0.0 milestone Feb 18, 2023
@gustavohenke gustavohenke mentioned this issue Feb 18, 2023
5 tasks
@gustavohenke gustavohenke linked a pull request Feb 18, 2023 that will close this issue
5 tasks
@tejastomarbyte
Copy link

I would like to work on this issue!

@gustavohenke
Copy link
Member

hi @tejastomarbyte, take a look at #1214 🙂
Any comments or improvements are welcome!

@gustavohenke
Copy link
Member

Hi hi, https://github.com/express-validator/express-validator/releases/tag/v7.0.0 is out with a fix for this 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants