KuzzleRequest Events #
API requests sent by clients go through the following events, in this order:
- request:beforeExecution
- request:onAuthorized or request:onUnauthorized
- request:onExecution
- before events, the API action itself, then after events or error events
- request:onSuccess or request:onError
- request:afterExecution
All these events are pipes: handlers may modify the payload, and must resolve to it.
request:afterExecution #
| Arguments | Type | Description |
|---|---|---|
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:
| Properties | Type | Description |
|---|---|---|
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 #
| Arguments | Type | Description |
|---|---|---|
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 #
| Arguments | Type | Description |
|---|---|---|
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 #
| Arguments | Type | Description |
|---|---|---|
request | KuzzleRequest | The normalized API request |
Triggered whenever a request execution fails.
This event occurs after error events.
request:onExecution #
| Arguments | Type | Description |
|---|---|---|
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 #
| Arguments | Type | Description |
|---|---|---|
request | KuzzleRequest | The normalized API request |
Triggered whenever a request execution succeeds.
This event occurs after after events.
request:onUnauthorized #
| Arguments | Type | Description |
|---|---|---|
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
401error for the anonymous user,403otherwise; - Kuzzle runs in failsafe mode and the user is not an administrator.