{"record":{"id":"5015bbaa178673b6","repo":"apify/crawlee","slug":"too-many-redirects-maxredirects-while-request","errorCode":null,"errorMessage":"Too many redirects (${maxRedirects}) while requesting ${currentRequest.url}","messagePattern":"Too many redirects \\((.+?)\\) while requesting (.+?)","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/http-client/src/base-http-client.ts","lineNumber":209,"sourceCode":"        currentRequest = initialRequest.clone();\n\n        while (true) {\n            await this.applyCookies(currentRequest, cookieJar);\n\n            const response = await this.fetch(currentRequest, {\n                signal,\n                proxyUrl,\n                cookieJar,\n                fingerprint,\n                ignoreTlsErrors,\n                redirect: 'manual',\n            });\n\n            await this.setCookies(response, cookieJar);\n\n            if (this.isRedirect(response)) {\n                if (redirectCount++ >= maxRedirects) {\n                    throw new Error(`Too many redirects (${maxRedirects}) while requesting ${currentRequest.url}`);\n                }\n                currentRequest = this.buildRedirectRequest(currentRequest, response, initialRequest);\n                continue;\n            }\n\n            return response;\n        }\n    }\n}\n","sourceCodeStart":191,"sourceCodeEnd":219,"githubUrl":"https://github.com/apify/crawlee/blob/dbe57fb09ca607ad59dcf998f3925ef9ac3bb26c/packages/http-client/src/base-http-client.ts#L191-L219","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Increase `maxRedirects` in the client/request options if the chain is legitimately long","Inspect the redirect chain (log Location headers) to find the loop","Send required cookies/auth headers so the server stops redirecting","Request the final URL directly if the chain is deterministic"],"exampleFix":"// before\nconst client = new MyHttpClient({ maxRedirects: 3 }); // loop at example.com\n// after\nconst client = new MyHttpClient({\n  maxRedirects: 10,\n  beforeRedirect: (req, res) => console.log(res.headers.location),\n});","handlingStrategy":"retry","validationCode":"null","typeGuard":"null","tryCatchPattern":"try {\n  return await client.sendRequest(request);\n} catch (err) {\n  if (/Too many redirects/.test(String(err))) {\n    logger.warning('Redirect loop suspected', { url: request.url });\n    return null; // or retry with cookies fixed / final URL\n  }\n  throw err;\n}","preventionTips":["Set maxRedirects generously (5-10) for real-world chains","Ensure cookies are enabled and replayed across redirects","Log Location headers to detect loops early","Request canonical final URLs directly when known"],"tags":["http","redirect","network"],"backgroundTag":"too-many-redirects","analyzedSha":"dbe57fb09ca607ad59dcf998f3925ef9ac3bb26c","analyzedAt":"2026-08-30T22:22:28.328Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}