apify/crawlee · error · Error

Too many redirects (${maxRedirects}) while requesting ${curr

Error message

Too many redirects (${maxRedirects}) while requesting ${currentRequest.url}

What it means

BaseHttpClient.sendRequest enforces a redirect limit (`maxRedirects`); when a response chain exceeds it, it throws with the limit and the URL of the last request. This guards against infinite redirect loops (common with cookie/session issues or misconfigured servers).

Source

Thrown at packages/http-client/src/base-http-client.ts:209

        currentRequest = initialRequest.clone();

        while (true) {
            await this.applyCookies(currentRequest, cookieJar);

            const response = await this.fetch(currentRequest, {
                signal,
                proxyUrl,
                cookieJar,
                fingerprint,
                ignoreTlsErrors,
                redirect: 'manual',
            });

            await this.setCookies(response, cookieJar);

            if (this.isRedirect(response)) {
                if (redirectCount++ >= maxRedirects) {
                    throw new Error(`Too many redirects (${maxRedirects}) while requesting ${currentRequest.url}`);
                }
                currentRequest = this.buildRedirectRequest(currentRequest, response, initialRequest);
                continue;
            }

            return response;
        }
    }
}

View on GitHub (pinned to dbe57fb09c)

Solutions

  1. Increase `maxRedirects` in the client/request options if the chain is legitimately long
  2. Inspect the redirect chain (log Location headers) to find the loop
  3. Send required cookies/auth headers so the server stops redirecting
  4. Request the final URL directly if the chain is deterministic

Example fix

// before
const client = new MyHttpClient({ maxRedirects: 3 }); // loop at example.com
// after
const client = new MyHttpClient({
  maxRedirects: 10,
  beforeRedirect: (req, res) => console.log(res.headers.location),
});
Defensive patterns

Strategy: retry

Validate before calling

null

Type guard

null

Try / catch

try {
  return await client.sendRequest(request);
} catch (err) {
  if (/Too many redirects/.test(String(err))) {
    logger.warning('Redirect loop suspected', { url: request.url });
    return null; // or retry with cookies fixed / final URL
  }
  throw err;
}

Prevention

When it happens

Trigger: A server responding with more redirects than maxRedirects allows, redirect loops (A -> B -> A), or cookies not being replayed so a login/consent redirect repeats forever.

Common situations: Sites redirecting to themselves due to missing/expired cookies or bot detection; wrong maxRedirects for a chain-heavy site; http->https->www redirect chains combined with loopbacks.

Related errors


AI-assisted analysis of apify/crawlee@dbe57fb09c (2026-08-30). Data as JSON: /api/errors/5015bbaa178673b6. Report an issue: GitHub.