Core
Framework v2.x
2

validate #

Validates the content of a request body (mutates the request).

Arguments #

Copied to clipboard!
validate(request: KuzzleRequest, verbose: boolean): Promise<any>;

Arguments Type Description
request KuzzleRequest KuzzleRequest object with a non-empty body content
verbose
boolean
If true, returns an exhaustive validation report, instead of failing at the first encountered error

Return #

The validate function returns a promise, and if relevant, default values are applied to the provided request.

If a validation error occurs, the behavior depends on the validation optional parameter:

  • false (default): the promise is rejected with the first encountered error
  • true: the promise is resolved even if the validation fails. The promise resolves a validation status report, containing the following properties:
    • validation: {boolean} validation state
    • errorMessages: {array} the exhaustive list of encountered errors