KuzzleRequest Events #

API requests sent by clients go through the following events, in this order:

  1. request:beforeExecution
  2. request:onAuthorized or request:onUnauthorized
  3. request:onExecution
  4. before events, the API action itself, then after events or error events
  5. request:onSuccess or request:onError
  6. request:afterExecution

All these events are pipes: handlers may modify the payload, and must resolve to it.

request:afterExecution #

Available since 2.19.0
ArgumentsTypeDescription
payload
object
Request execution outcome, see below

Triggered once a client request has been executed, whether it succeeded or failed, including when it was rejected before reaching its controller (rights check, rate limit, failing pipe).

Also triggered by requests executed with the EmbeddedSDK and the triggerEvents option. In that case, the value the pipe resolves to is ignored.

The provided payload object has the following properties:

PropertiesTypeDescription
request
KuzzleRequest
The executed request
success
boolean
true if the request succeeded
result
any
Result sent back to the client (only on success)
error
Error
Error sent back to the client (only on failure)

Pipes must resolve to an object of the same shape: on success, its result is sent to the client; on failure, its error is sent to the client.

request:beforeExecution #

Available since 2.14.0
ArgumentsTypeDescription
request
KuzzleRequest
The normalized API request

Triggered when a client request starts its execution, before the rights check. The user is not authenticated yet: request.context.user and request.context.token are not set.

request:onAuthorized #

ArgumentsTypeDescription
request
KuzzleRequest
The normalized API request

Triggered whenever a request passes authorization checks and is ready to be processed.

This event occurs before request:onExecution and before events.

request:onError #

ArgumentsTypeDescription
request
KuzzleRequest
The normalized API request

Triggered whenever a request execution fails.

This event occurs after error events.

request:onExecution #

Available since 2.38.0
ArgumentsTypeDescription
request
KuzzleRequest
The normalized API request

Triggered right before the before events of the executed API action, once the request passed the rights check and the rate limiter.

Also triggered by requests executed with the EmbeddedSDK and the triggerEvents option.

request:onSuccess #

ArgumentsTypeDescription
request
KuzzleRequest
The normalized API request

Triggered whenever a request execution succeeds.

This event occurs after after events.

request:onUnauthorized #

ArgumentsTypeDescription
request
KuzzleRequest
The normalized API request

Triggered whenever a request fails authorization checks and is about to be rejected. This happens when:

  • the authentication token cannot be verified (invalid or expired token);
  • the user is not allowed to execute the action: the request is rejected with a 401 error for the anonymous user, 403 otherwise;
  • Kuzzle runs in failsafe mode and the user is not an administrator.