Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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