Skip to content

Commit

Permalink
docs: note that async custom validators must reject
Browse files Browse the repository at this point in the history
Closes #744
  • Loading branch information
gustavohenke committed Nov 28, 2019
1 parent eba8e46 commit d82af97
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion docs/api-validation-chain.md
Expand Up @@ -66,7 +66,9 @@ Receives the value of the field being validated, as well as the express request,
> *Returns:* the current validation chain instance
Adds a custom validator to the current validation chain.
The custom validator may return a promise to indicate an async validation task. In case it's rejected, the field is considered invalid.
The custom validator may return a promise to indicate an async validation task.
- If it's rejected, the field is considered invalid;
- If it's resolved, the field is considered valid **regardless of the returned value**.

This comment has been minimized.

Copy link
@Poyoman39

Poyoman39 Nov 28, 2019

Nice precision ;)


The custom validator may also throw JavaScript exceptions (eg `throw new Error()`) and return falsy values to indicate the field is invalid.

Expand Down
2 changes: 2 additions & 0 deletions docs/feature-custom-validators-sanitizers.md
Expand Up @@ -16,6 +16,8 @@ It takes a validator function.
Custom validators may return Promises to indicate an async validation (which will be awaited upon),
or `throw` any value/reject a promise to [use a custom error message](feature-error-messages.md#custom-validator-level).

> **Note:** if your custom validator returns a promise, it must reject to indicate that the field is invalid.
### Example: checking if e-mail is in use
```js
const { body } = require('express-validator');
Expand Down

0 comments on commit d82af97

Please sign in to comment.