mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Retry failed NexusAPI calls.
This commit is contained in:
parent
d20de58f50
commit
412d854160
@ -95,5 +95,6 @@ namespace Wabbajack.Common
|
||||
|
||||
public static string WabbajackCacheHostname = "build.wabbajack.org";
|
||||
public static int WabbajackCachePort = 80;
|
||||
public static int MaxHTTPRetries = 4;
|
||||
}
|
||||
}
|
||||
|
@ -222,14 +222,28 @@ namespace Wabbajack.Lib.NexusApi
|
||||
|
||||
public async Task<T> Get<T>(string url)
|
||||
{
|
||||
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())
|
||||
int retries = 0;
|
||||
TOP:
|
||||
try
|
||||
{
|
||||
return stream.FromJSON<T>();
|
||||
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())
|
||||
{
|
||||
return stream.FromJSON<T>();
|
||||
}
|
||||
}
|
||||
catch (TimeoutException)
|
||||
{
|
||||
if (retries == Consts.MaxHTTPRetries)
|
||||
throw;
|
||||
Utils.Log($"Nexus call to {url} failed, retrying {retries} of {Consts.MaxHTTPRetries}");
|
||||
retries++;
|
||||
goto TOP;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user