{"record":{"id":"82579bdf7b537fe8","repo":"NickeManarin/ScreenToGif","slug":"error-while-trying-to-get-the-latest-release-r","errorCode":null,"errorMessage":"Error while trying to get the latest release: \r\n{response.ReasonPhrase}","messagePattern":"Error while trying to get the latest release: \r\n(.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"warning","filePath":"ScreenToGif.Util/GitHubHelper.cs","lineNumber":20,"sourceCode":"using ScreenToGif.Util.Settings;\nusing System.Text.Json;\n\nnamespace ScreenToGif.Util;\n\npublic static class GitHubHelper\n{\n    public static async Task<GitHubRelease> GetLatestRelease(string repository)\n    {\n        if (string.IsNullOrWhiteSpace(repository))\n            throw new ArgumentNullException(nameof(repository));\n\n        using var client = WebHelper.GetHttpClient();\n        client.DefaultRequestHeaders.Add(\"User-Agent\", \"ScreenToGif/\" + UserSettings.All.VersionText);\n\n        using var response = await client.GetAsync($\"https://api.github.com/repos/{repository}/releases/latest\");\n\n        if (!response.IsSuccessStatusCode)\n            throw new Exception(\"Error while trying to get the latest release: \" + Environment.NewLine + response.ReasonPhrase);\n\n        var content = await response.Content.ReadAsStringAsync();\n\n        return JsonSerializer.Deserialize<GitHubRelease>(content);\n    }\n\n    public static GitHubAsset GetAsset(this GitHubRelease release, string assetName)\n    {\n        if (release is null)\n            throw new ArgumentNullException(nameof(release));\n\n        if (string.IsNullOrWhiteSpace(assetName))\n            throw new ArgumentNullException(nameof(assetName));\n\n        return release.Assets.FirstOrDefault(x => x.Name.Contains(assetName, StringComparison.InvariantCultureIgnoreCase));\n    }\n}","sourceCodeStart":2,"sourceCodeEnd":37,"githubUrl":"https://github.com/NickeManarin/ScreenToGif/blob/a4d0a67c2131cd048ceec86cd40afc2f1a06f2fd/ScreenToGif.Util/GitHubHelper.cs#L2-L37","documentation":"Thrown by GitHubHelper.GetLatestRelease when the GitHub releases API endpoint returns a non-success HTTP status code. The method constructs a URL from the repository parameter and deserializes the JSON into a GitHubRelease object. Any non-2xx response triggers this exception with the HTTP reason phrase.","triggerScenarios":"GET https://api.github.com/repos/{repository}/releases/latest returns non-2xx. Common status codes: 403 (rate limit exceeded — 60 requests/hour unauthenticated), 404 (repository not found or has no releases), 503 (GitHub server error). The repository parameter may be malformed or the repo renamed.","commonSituations":"Application checks for updates too frequently, hitting the 60/hour unauthenticated rate limit. Repository was renamed or the owner changed. GitHub API is temporarily down. The 'repository' argument is wrong (e.g., missing owner/repo format). No releases have been published yet (404).","solutions":["Check the response status code and reason phrase — 403 means rate limit, 404 means repo/no-release.","Cache the last-known release locally and use it when the API is rate-limited.","Add authentication (GitHub token) to raise the rate limit from 60 to 5000 requests/hour.","Wrap the call in a try-catch and silently skip update checks on failure rather than crashing."],"exampleFix":"// before\nif (!response.IsSuccessStatusCode)\n    throw new Exception(\"Error while trying to get the latest release: \" + Environment.NewLine + response.ReasonPhrase);\n\n// after: include status code for actionable diagnostics\nif (!response.IsSuccessStatusCode)\n    throw new HttpRequestException($\"Error while trying to get the latest release: {(int)response.StatusCode} {response.ReasonPhrase}\");","handlingStrategy":"try-catch","validationCode":"// Check rate limit before calling\nvar client = WebHelper.GetHttpClient();\nclient.DefaultRequestHeaders.Add(\"User-Agent\", \"ScreenToGif/\" + UserSettings.All.VersionText);\nvar limitResponse = await client.GetAsync(\"https://api.github.com/rate_limit\");\nif (limitResponse.IsSuccessStatusCode)\n{\n    var limits = JsonSerializer.Deserialize<JsonDocument>(await limitResponse.Content.ReadAsStringAsync());\n    var remaining = limits.RootElement.GetProperty(\"rate\").GetProperty(\"remaining\").GetInt32();\n    if (remaining == 0) return lastCachedRelease;\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    var release = await GitHubHelper.GetLatestRelease(repository);\n    _cachedRelease = release;\n    return release;\n}\ncatch (Exception)\n{\n    return _cachedRelease; // use last known good release, or null\n}","preventionTips":["Cache the latest release result so repeated update checks don't re-hit the API.","Throttle update checks (e.g., once per day, not on every startup) to avoid rate limits.","Add a GitHub token header to raise the rate limit ceiling when possible."],"tags":["network","github-api","update-check","http","rate-limit"],"backgroundTag":null,"analyzedSha":"a4d0a67c2131cd048ceec86cd40afc2f1a06f2fd","analyzedAt":"2026-08-13T11:12:06.147Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}