Function callDonationAlertsApi

  • Makes an HTTP call to the Donation Alerts API and processes the response.

    Type Parameters

    • T

      The expected type of the response data.

    Parameters

    • options: DonationAlertsApiCallOptions

      The configuration of the API call, such as URL, method, query parameters, and body.

    • OptionalaccessToken: string

      The OAuth access token to authorize the request. If not provided, the request may fail unless the endpoint does not require authentication.

    • fetchOptions: DonationAlertsCallFetchOptions = {}

      Additional configuration for the Fetch API, such as credentials, cache, etc.

    Returns Promise<T>

    A promise that resolves to the transformed response of type T.

    This function builds on callDonationAlertsApiRaw by handling errors and transforming the response. It ensures responses with non-success status codes (e.g., 400, 500) are properly handled and raises an HttpError, allowing you to manage errors gracefully in your application.

    The response is transformed into the expected data type (T) if the call succeeds.

    HttpError if the response has a non-success HTTP status code (outside 200-299 range).

    try {
    const data = await callDonationAlertsApi<{ id: number; name: string }>(
    { url: 'user/oauth', type: 'api' },
    'your-access-token'
    );

    console.log(data);
    } catch (e) {
    console.error('Failed to fetch user:', e);
    }