Logos DX
    Preparing search index...

    Type Alias FetchResponse<T, H, P, RH>

    FetchResponse:
        | FetchResponseBase<H, P, RH> & { data: T; ok: true }
        | FetchResponseBase<H, P, RH> & { data: unknown; ok: false }

    Enhanced response object that provides comprehensive information about a fetch request and its result.

    A discriminated union on ok: a 2xx exchange narrows data to T, while a non-2xx exchange narrows data to unknown — the compiler forces the res.ok check before data can be trusted as T. Every completed HTTP exchange resolves this way; only a transport failure (abort, timeout, connection lost, parse failure on ok: true) rejects as a FetchError.

    Type Parameters

    • T = any

      Type of the parsed response data (only on the ok: true branch)

    • H = InstanceHeaders

      Type of request headers used in the config

    • P = InstanceParams

      Type of request params used in the config

    • RH = InstanceResponseHeaders

      Type of response headers received from the server

    // Narrow on `ok` before destructuring `data`
    const response = await api.get<User>('/users/123');
    if (!response.ok) throw new Error(`Request failed: ${response.status}`);

    const { data: user } = response;
    // Narrow on `ok` before trusting `data` as `T`
    const [response, err] = await attempt(() => api.get<User[]>('/users'));
    if (err) {
    console.error('Transport failure:', err);
    return;
    }

    if (!response.ok) {
    console.warn('Non-2xx response:', response.status, response.data);
    return;
    }

    console.log('Success:', response.data);