Skip to content

Instantly share code, notes, and snippets.

@jfversluis
Created May 17, 2018 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfversluis/10d315a39e94312be46d910770eec1b1 to your computer and use it in GitHub Desktop.
Save jfversluis/10d315a39e94312be46d910770eec1b1 to your computer and use it in GitHub Desktop.
Smarter approach for our requests
return await Policy
.Handle<HttpRequestException>(ex => !ex.Message.ToLower().Contains("404"))
.WaitAndRetryAsync
(
retryCount: 3,
sleepDurationProvider: retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)),
onRetry: (ex, time) =>
{
Console.WriteLine($"Something went wrong: {ex.Message}, retrying...");
}
)
.ExecuteAsync(async () =>
{
Console.WriteLine($"Trying to fetch remote data...");
var resultJson = await _httpClient.GetStringAsync($"comic/{id}");
return JsonConvert.DeserializeObject<IEnumerable<Comic>>(resultJson);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment