glanceapp/glance · error
unexpected status code %d when requesting challenge page
Error message
unexpected status code %d when requesting challenge page
What it means
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.
Source
Thrown at internal/glance/widget-reddit.go:404
})
}()
func fetchRedditLoidCookie() (string, error) {
request, err := http.NewRequest("GET", "https://www.reddit.com/", nil)
if err != nil {
return "", err
}
setBrowserUserAgentHeader(request)
response, err := redditHTTPClient.Do(request)
if err != nil {
return "", err
}
defer response.Body.Close()
if response.StatusCode != http.StatusOK {
return "", fmt.Errorf("unexpected status code %d when requesting challenge page", response.StatusCode)
}
challengeBody, err := io.ReadAll(response.Body)
if err != nil {
return "", err
}
challengeMatches := redditChallengePattern.FindSubmatch(challengeBody)
tokenMatches := redditTokenPattern.FindSubmatch(challengeBody)
if challengeMatches == nil {
return "", fmt.Errorf("no JS challenge found")
}
if tokenMatches == nil {
return "", fmt.Errorf("no token found in challenge page")
}
View on GitHub (pinned to 91324e8de7)
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
Example fix
# before
- type: reddit
subreddit: programming
cache: 5m
# after
- type: reddit
subreddit: programming
cache: 1h
app-access-token:
client-id: <id>
client-secret: <secret> Defensive patterns
Strategy: retry
Try / catch
loid, err := solveRedditChallenge(client)
if err != nil {
if strings.Contains(err.Error(), "unexpected status code") {
// back off: Reddit is blocking/rate limiting; retry next cycle with longer cache
widget.retryAfter = time.Hour
return
}
return
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- unexpected status code %d when submitting challenge solution
- could not solve reddit challenge
- %w: could not get repository details: %s
- subreddit is required
- no `{REQUEST-URL}` placeholder specified
AI-assisted analysis of glanceapp/glance@91324e8de7 (2026-08-15).
Data as JSON: /api/errors/4c4fd418a1798e88.
Report an issue: GitHub.