{"record":{"id":"1925cc6dd50a440f","repo":"BeyondDimension/SteamTools","slug":"failed-to-obtain-badge-information-status-code-s","errorCode":null,"errorMessage":"Failed to obtain badge information status code: {status}","messagePattern":"Failed to obtain badge information status code: (.+?)","errorType":"exception","errorClass":"HttpRequestException","httpStatus":null,"severity":"error","filePath":"src/BD.WTTS.Client.Plugins.SteamIdleCard/UI/ViewModels/IdleCardPageViewModel.cs","lineNumber":411,"sourceCode":"            var steam_id = SteamLoginState.SteamId.ToString();\n            (UserIdleInfo, badges, status) = await IdleCard.GetBadgesAsync(steam_id, true);\n            if (status == HttpStatusCode.Forbidden)\n            {\n                var result = await TextBoxWindowViewModel.ShowDialogAsync(new TextBoxWindowViewModel\n                {\n                    Title = Strings.Idle_NeedParentalPIN,\n                    Placeholder = \"PIN CODE\",\n                    InputType = TextBoxWindowViewModel.TextBoxInputType.Password,\n                });\n                if (!string.IsNullOrEmpty(result))\n                {\n                    await steamSession.UnlockParental(steam_id, result);\n                    goto GetBadges;\n                }\n                throw new ArgumentNullException(Strings.Idle_PIN_NotBeNull);\n            }\n            else if (status != HttpStatusCode.OK)\n                throw new HttpRequestException($\"{Strings.Idle_GetBadgesError} status code: {status}\");\n            goto HandleBadges;\n\n        HandleBadges:\n            Badges.Clear();\n            Badges.Add(badges!);\n            //await RefreshPrivateGameAppIds(steam_id);\n            TotalCardsRemaining = 0;\n            TotalCardsAvgPrice = 0;\n\n            badges = badges!.Where(w => w.CardsRemaining != 0);\n\n            foreach (var badge in badges)\n            {\n                if (IsExcludedApp(badge.AppId))\n                    continue;\n\n                TotalCardsAvgPrice += badge.RegularAvgPrice * badge.CardsRemaining;\n                TotalCardsRemaining += badge.CardsRemaining;","sourceCodeStart":393,"sourceCodeEnd":429,"githubUrl":"https://github.com/BeyondDimension/SteamTools/blob/c16ffa08e03b192d23ada290c4969e77f9201f3d/src/BD.WTTS.Client.Plugins.SteamIdleCard/UI/ViewModels/IdleCardPageViewModel.cs#L393-L429","documentation":"Thrown (as HttpRequestException) when the Steam badge request returns a status code that is neither OK (200) nor the parental-lock code. The message includes the localized 'get badges error' text plus the actual status code so the caller knows exactly what Steam returned.","triggerScenarios":"Calling the badges endpoint and receiving any non-OK, non-parental status — e.g. 401/403 (auth expired), 429 (rate limited), 500/503 (Steam error), or 0 (network failure surfaced as a non-OK code).","commonSituations":"Steam session/login token expired; rate limited from too many requests; Steam backend temporarily down; region/network blocking the request; account changed causing auth failure.","solutions":["If 401/403, re-login to Steam to refresh the session token, then retry the badge fetch.","If 429, back off and retry after a delay (respect Steam rate limits).","If 5xx/0, wait and retry — Steam backend or network is temporarily unavailable.","Surface the status code to the user with guidance (re-login / retry) instead of a raw exception."],"exampleFix":"// before\nelse if (status != HttpStatusCode.OK)\n    throw new HttpRequestException($\"{Strings.Idle_GetBadgesError} status code: {status}\");\n\n// after: typed handling with retry guidance\nelse if (status != HttpStatusCode.OK)\n{\n    if (status == HttpStatusCode.Unauthorized || status == HttpStatusCode.Forbidden)\n        throw new HttpRequestException(\"Steam session expired; please re-login.\");\n    if ((int)status == 429)\n        throw new HttpRequestException(\"Rate limited by Steam; retry later.\");\n    throw new HttpRequestException($\"{Strings.Idle_GetBadgesError} status code: {status}\");\n}","handlingStrategy":"retry","validationCode":"// Pre-flight: ensure the Steam session is still valid before fetching badges.\nif (await steamSession.IsSessionValidAsync() != true)\n    throw new InvalidOperationException(\"Steam session expired; please re-login.\");\n\n// Rate-limit guard: avoid hammering the badges endpoint.\nif (DateTime.UtcNow - lastBadgeFetch < TimeSpan.FromSeconds(5))\n    throw new InvalidOperationException(\"Badge fetch rate-limited locally; retry shortly.\");","typeGuard":null,"tryCatchPattern":"try { badges = await FetchBadgesAsync(ct); }\ncatch (HttpRequestException ex) when (ex.Message.Contains(\"status code\"))\n{\n    var code = ExtractStatusCode(ex.Message);\n    if (code is 401 or 403) { await ReLoginSteamAsync(); goto retry; }   // auth expired\n    if (code == 429 || (int)code >= 500) { await Task.Delay(backoff, ct); goto retry; } // transient\n    Log.Error($\"Steam badge fetch failed: HTTP {code}\");\n    throw;\n}","preventionTips":["Validate the Steam session/login token before each badge fetch and re-login on 401/403.","Throttle badge requests to avoid 429 rate limiting from Steam.","Retry transient statuses (429, 5xx) with exponential backoff.","Surface the status code to the user with concrete guidance (re-login / retry later)."],"tags":["steam","idle-card","http","status-code"],"backgroundTag":null,"analyzedSha":"c16ffa08e03b192d23ada290c4969e77f9201f3d","analyzedAt":"2026-08-13T11:52:20.410Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}