Skip to main content
Version: 3.x.x

Interceptors

You can intercept responses or requests before they are handled by any other module. This way you can hook-in to different available interceptors. They are added on a particular client, you can chain-add them.

Interceptors can be deactivated on selected requests thanks to the options passed to them. To do this, use the disableRequestInterceptors and disableResponseInterceptors.


Request interceptors

You can add an interceptor to every request executed within a given client and overwrite the sent data or execute your own logic.

export const client = new Client({ url }).onRequest(async (response, request) => {
// Add your custom logic

return response;
});

Response interceptors

With response interceptors, you can call your own logic and change the returned data before it is handled in the system.

onSuccess

export const client = new Client({ url }).onSuccess(async (response, request) => {
// Add your custom logic

return response;
});

onError

export const client = new Client({ url }).onError(async (response, request) => {
// Add your custom logic

return response;
});

onResponse

export const client = new Client({ url }).onResponse(async (response, request) => {
// Add your custom logic

return response;
});