Created
May 17, 2018 12:52
-
-
Save jfversluis/10d315a39e94312be46d910770eec1b1 to your computer and use it in GitHub Desktop.
Smarter approach for our requests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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