diff --git a/Wabbajack.Common/Consts.cs b/Wabbajack.Common/Consts.cs index b2f4a121c..05ca09751 100644 --- a/Wabbajack.Common/Consts.cs +++ b/Wabbajack.Common/Consts.cs @@ -95,5 +95,6 @@ public static string UserAgent public static string WabbajackCacheHostname = "build.wabbajack.org"; public static int WabbajackCachePort = 80; + public static int MaxHTTPRetries = 4; } } diff --git a/Wabbajack.Lib/NexusApi/NexusApi.cs b/Wabbajack.Lib/NexusApi/NexusApi.cs index 5eb1b9c25..4365a6c3c 100644 --- a/Wabbajack.Lib/NexusApi/NexusApi.cs +++ b/Wabbajack.Lib/NexusApi/NexusApi.cs @@ -222,14 +222,28 @@ public static async Task Get(string apiKey = null) public async Task Get(string url) { - var response = await HttpClient.GetAsync(url, HttpCompletionOption.ResponseHeadersRead); - UpdateRemaining(response); - if (!response.IsSuccessStatusCode) - throw new HttpRequestException($"{response.StatusCode} - {response.ReasonPhrase}"); + int retries = 0; + TOP: + try + { + var response = await HttpClient.GetAsync(url, HttpCompletionOption.ResponseHeadersRead); + UpdateRemaining(response); + if (!response.IsSuccessStatusCode) + throw new HttpRequestException($"{response.StatusCode} - {response.ReasonPhrase}"); + - using (var stream = await response.Content.ReadAsStreamAsync()) + using (var stream = await response.Content.ReadAsStreamAsync()) + { + return stream.FromJSON(); + } + } + catch (TimeoutException) { - return stream.FromJSON(); + if (retries == Consts.MaxHTTPRetries) + throw; + Utils.Log($"Nexus call to {url} failed, retrying {retries} of {Consts.MaxHTTPRetries}"); + retries++; + goto TOP; } }