Core
Framework v2.x
2

validate #

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

Arguments #

validate(request: KuzzleRequest, verbose?: boolean): Promise<KuzzleRequest | { errorMessages: JSONObject, valid: boolean }>;

ArgumentsTypeDescription
request
KuzzleRequest
KuzzleRequest object with a non-empty body content
verbose
boolean
Optional, default false. If true, returns an exhaustive validation report, instead of failing at the first encountered error

Return #

The behavior depends on the verbose parameter:

  • false (default): if the validation succeeds, the promise resolves to the request itself, with the default values of the specifications applied to its body. Otherwise, the promise is rejected with the first encountered error.
  • true: the promise is resolved even if the validation fails, and the request is left unchanged. The promise resolves to a validation report, containing the following properties:
    • valid: {boolean} validation state
    • errorMessages: {object} the exhaustive list of encountered errors