-
-
Notifications
You must be signed in to change notification settings - Fork 616
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
Made customSanitizer await for async functions #919
Made customSanitizer await for async functions #919
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Draft is already looking good to me!
What do you suggest that we do with the errors?
I'd suggest automatically send a 500 http error code and abort the request at all. Adding the error to the error list given by |
Co-authored-by: Gustavo Henke <guhenke@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! I think that an error will already cascade up to the route definition, so this LGTM as is.
Out in |
Thanks for the feature. Should the document at https://express-validator.github.io/docs/custom-validators-sanitizers.html#custom-sanitizers be updated? |
Sure @wwei-flux, you can raise a PR if you want! |
I made this little tweak to make possible use customSanitize in async environments. I did not made a proper error handler because I don't know how to integrate that with the validators, so I don't think the work of this feature is done, that's just a draft. This is related to #784
An example use case for this would be:
body('user').customSanitizer(async(id) => await users.findById(id))
Also made the tests for that