{"record":{"id":"4c4fd418a1798e88","repo":"glanceapp/glance","slug":"unexpected-status-code-d-when-requesting-challeng","errorCode":null,"errorMessage":"unexpected status code %d when requesting challenge page","messagePattern":"unexpected status code (.+?) when requesting challenge page","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/glance/widget-reddit.go","lineNumber":404,"sourceCode":"\t})\n}()\n\nfunc fetchRedditLoidCookie() (string, error) {\n\trequest, err := http.NewRequest(\"GET\", \"https://www.reddit.com/\", nil)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\tsetBrowserUserAgentHeader(request)\n\n\tresponse, err := redditHTTPClient.Do(request)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tdefer response.Body.Close()\n\n\tif response.StatusCode != http.StatusOK {\n\t\treturn \"\", fmt.Errorf(\"unexpected status code %d when requesting challenge page\", response.StatusCode)\n\t}\n\n\tchallengeBody, err := io.ReadAll(response.Body)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\tchallengeMatches := redditChallengePattern.FindSubmatch(challengeBody)\n\ttokenMatches := redditTokenPattern.FindSubmatch(challengeBody)\n\n\tif challengeMatches == nil {\n\t\treturn \"\", fmt.Errorf(\"no JS challenge found\")\n\t}\n\n\tif tokenMatches == nil {\n\t\treturn \"\", fmt.Errorf(\"no token found in challenge page\")\n\t}\n","sourceCodeStart":386,"sourceCodeEnd":422,"githubUrl":"https://github.com/glanceapp/glance/blob/91324e8de762702e97b0ac5c8e36271d644d8642/internal/glance/widget-reddit.go#L386-L422","documentation":"While solving Reddit's JS bot challenge, the challenge page request (via redditHTTPClient with a browser User-Agent) returned a status other than 200. Reddit serves its challenge at 200; getting 403/429/5xx means Reddit is blocking or rate limiting the client before even issuing the challenge.","triggerScenarios":"Reddit returns 403 (IP/ASN blocked, datacenter egress), 429 (rate limited from repeated widget updates), or 5xx during Reddit incidents; also happens when reddit.com redirects to a login/blocked page.","commonSituations":"Self-hosting glance on a VPS whose IP range Reddit blocks; very short cache duration causing frequent reddit fetches and rate limiting; Reddit outages; shared NAT IPs with abuse history.","solutions":["Configure app auth (client-id/client-secret) on the reddit widget so the challenge flow is bypassed for API calls","Increase the widget's cache duration to reduce request frequency","Route egress via a residential IP or proxy Reddit does not block","During Reddit-side incidents, wait and retry on the next update cycle"],"exampleFix":"# before\n- type: reddit\n  subreddit: programming\n  cache: 5m\n# after\n- type: reddit\n  subreddit: programming\n  cache: 1h\n  app-access-token:\n    client-id: <id>\n    client-secret: <secret>","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"loid, err := solveRedditChallenge(client)\nif err != nil {\n    if strings.Contains(err.Error(), \"unexpected status code\") {\n        // back off: Reddit is blocking/rate limiting; retry next cycle with longer cache\n        widget.retryAfter = time.Hour\n        return\n    }\n    return\n}","preventionTips":["Configure app auth on the reddit widget to bypass the challenge flow entirely","Set a long cache duration (1h+) to stay under Reddit's rate limits","Avoid hosting glance on IP ranges Reddit aggressively blocks; use a proxy if needed"],"tags":["reddit","rate-limit","bot-detection","http-status"],"backgroundTag":null,"analyzedSha":"91324e8de762702e97b0ac5c8e36271d644d8642","analyzedAt":"2026-08-15T14:12:54.279Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}