Libraries
    Preparing search index...

    Interface ClientHooks

    Lifecycle hooks that are invoked at various stages of a request.

    All hook arrays are executed serially in order. Hooks can be synchronous or asynchronous.

    interface ClientHooks {
        afterResponse?: (
            (
                request: { init: RequestInit; url: string },
                response: Response,
            ) => any
        )[];
        beforeError?: ((error: WebError) => WebError | Promise<WebError>)[];
        beforeRequest?: (
            (request: { init: RequestInit; url: string }) => void | Promise<void>
        )[];
        beforeRetry?: (
            (
                info: {
                    error: Error;
                    init: RequestInit;
                    retryCount: number;
                    url: string;
                },
            ) => void
            | Promise<void>
        )[];
    }
    Index

    Properties

    afterResponse?: (
        (request: { init: RequestInit; url: string }, response: Response) => any
    )[]

    Called after a successful response is received. Returning a Response replaces the original response.

    hooks: {
    afterResponse: [(req, res) => {
    console.log(`${req.init.method} ${req.url}${res.status}`);
    }],
    }
    beforeError?: ((error: WebError) => WebError | Promise<WebError>)[]

    Called before an error is thrown. Can transform or enrich the error before it reaches the caller. The returned error replaces the original.

    beforeRequest?: (
        (request: { init: RequestInit; url: string }) => void | Promise<void>
    )[]

    Called before every request is sent. Can be used to log, modify headers, or add tracing information.

    hooks: {
    beforeRequest: [(req) => {
    req.init.headers = {
    ...req.init.headers as Record<string, string>,
    'X-Request-Id': crypto.randomUUID(),
    };
    }],
    }
    beforeRetry?: (
        (
            info: {
                error: Error;
                init: RequestInit;
                retryCount: number;
                url: string;
            },
        ) => void
        | Promise<void>
    )[]

    Called before a retry attempt. Useful for logging retry attempts or modifying the request between retries.