Skip to content

Commit

Permalink
Add createError documentation. Fixes #999.
Browse files Browse the repository at this point in the history
  • Loading branch information
Marsup committed Jun 29, 2018
1 parent 8eefd0d commit 37d3588
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions API.md
Expand Up @@ -388,6 +388,14 @@ Extension objects use the following parameters :

Factory functions are advised if you intend to publish your extensions for others to use, because they are capable of using an extended joi being built, thus avoiding any erasure when using multiple extensions at the same time. See an example of a factory function in the section below.

Any of the `coerce`, `pre` and `validate` functions should use `this.createError(type, context, state, options[, flags])` to create and return errors.
This function potentially takes 5 arguments:
* `type` - the dotted type of the error matching predefined language elements or the ones defined in your extension. **Required**.
* `context` - a free-form object that can contain anything you want to provide context on regarding the error. This object's properties are inserted in the error message where bracketted placeholders are. **Required**.
* `state` - state that the validation was in, which contains the current key, path, parent if any, or reference if any. Usually you just have to pass the state you were given. **Required**.
* `options` - options that were used for the validation. Usually you just have to pass the options you were given. **Required**.
* `flags` - optional flags that you want to be shown for the error. Defaults to the schema's current flags.

#### npm note

If you publish your extension on npm, make sure to add `joi` and `extension` as keywords so that it's discoverable more easily.
Expand Down

0 comments on commit 37d3588

Please sign in to comment.