Contentful Personalization & Analytics
    Preparing search index...
    • Creates a FetchMethod that retries failed requests according to the provided configuration.

      Parameters

      Returns FetchMethod

      A FetchMethod that automatically retries qualifying failures.

      Error Thrown when the request cannot be retried and no successful response is obtained.

      This wrapper uses a lightweight internal retry loop and an AbortController to cancel pending requests when a non-retriable error occurs.

      const fetchWithRetry = createRetryFetchMethod({
      apiName: 'Optimization',
      retries: 3,
      intervalTimeout: 200,
      onFailedAttempt: ({ attemptNumber, retriesLeft }) => {
      console.warn(`Attempt ${attemptNumber} failed. Retries left: ${retriesLeft}`)
      },
      })

      const response = await fetchWithRetry('https://example.com', { method: 'GET' })