Contentful Personalization & Analytics
    Preparing search index...
    • Creates a FetchMethod that aborts requests after a configurable timeout.

      Parameters

      Returns FetchMethod

      A FetchMethod that enforces a timeout for each request.

      When a timeout occurs, the request is aborted using an AbortController. If onRequestTimeout is not provided, an error is logged by the package logger.

      const fetchWithTimeout = createTimeoutFetchMethod({
      apiName: 'Optimization',
      requestTimeout: 5000,
      onRequestTimeout: ({ apiName }) => {
      console.warn(`${apiName} request timed out`)
      },
      })

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