Skip to content

Commit

Permalink
Handle GitHub RateLimitExceededException
Browse files Browse the repository at this point in the history
  • Loading branch information
cengelha committed Apr 27, 2022
1 parent 35d6a02 commit 2859fc9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .github/changelogs/0.6.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This time with proper handling for the GitHub rate limit.

### Fixed
* Crash when GitHub rate limit (60 requests per hour for unauthenticated requests) is exceeded
13 changes: 9 additions & 4 deletions libNOM.map/Extensions/Http.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,25 @@ public static class HttpExtensions
/// <param name="name"></param>
/// <param name="asset"></param>
/// <returns>File content as string.</returns>
public static async Task<string> DownloadTextFileContentFromGitHubReleaseAsync(this HttpClient input, string owner, string name, string asset)
public static async Task<string?> DownloadTextFileContentFromGitHubReleaseAsync(this HttpClient input, string owner, string name, string asset)
{
var userAgent = Assembly.GetExecutingAssembly().GetName().Name;
var githubClient = new GitHubClient(new ProductHeaderValue(userAgent));

// Get the latest release from GitHub.
var release = await githubClient.Repository.Release.GetLatest(owner, name);
Release? release = null;
try
{
release = await githubClient.Repository.Release.GetLatest(owner, name);
}
catch (RateLimitExceededException) { }
if (release is null)
return string.Empty;
return null;

// Find the asset to download it.
var result = release.Assets.FirstOrDefault(a => a.Name.Equals(asset));
if (result is null)
return string.Empty;
return null;

var response = await input.GetAsync(result.BrowserDownloadUrl);
response.EnsureSuccessStatusCode();
Expand Down
2 changes: 1 addition & 1 deletion libNOM.map/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ libNOM.map.Mapping
libNOM.map.MappingSettings
libNOM.map.MappingSettings.PathDownload.get -> string!
libNOM.map.MappingSettings.PathDownload.init -> void
static libNOM.map.Extensions.HttpExtensions.DownloadTextFileContentFromGitHubReleaseAsync(this System.Net.Http.HttpClient! input, string! owner, string! name, string! asset) -> System.Threading.Tasks.Task<string!>!
static libNOM.map.Extensions.HttpExtensions.DownloadTextFileContentFromGitHubReleaseAsync(this System.Net.Http.HttpClient! input, string! owner, string! name, string! asset) -> System.Threading.Tasks.Task<string?>!
static libNOM.map.Mapping.Deobfuscate(Newtonsoft.Json.Linq.JObject! root) -> System.Collections.Generic.HashSet<string!>!
static libNOM.map.Mapping.Obfuscate(Newtonsoft.Json.Linq.JObject! root) -> void
static libNOM.map.Mapping.Settings.get -> libNOM.map.MappingSettings!
Expand Down
2 changes: 1 addition & 1 deletion libNOM.map/libNOM.map.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<RepositoryUrl>https://github.com/zencq/libNOM.map</RepositoryUrl>
<PackageReadmeFile>README.md</PackageReadmeFile>
<Version>0.6.0</Version>
<Version>0.6.1</Version>
<Description>Provides obfuscation and deobfuscation of save files from the game No Man's Sky.</Description>
<Authors>zencq</Authors>
<PackageLicenseExpression>GPL-3.0-only</PackageLicenseExpression>
Expand Down

0 comments on commit 2859fc9

Please sign in to comment.