-
-
Save stephenpatten/96f22c3b72015d69eb4cc8281bfc7606 to your computer and use it in GitHub Desktop.
Polly - Back Off and Retry on Error http client
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
//Retry http with a back off on failure | |
await Policy.Handle<HttpRequestException>().WaitAndRetryAsync(3, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt))) | |
.ExecuteAsync(async () => | |
{ | |
var result = await httpClient.GetAsync("api/CallToServer/" + varibleToSendToServer, cancellationToken); | |
if (result.IsSuccessStatusCode) | |
{ | |
returnValue = await result.Content.ReadAsAsync<List<Results>>(token); | |
} | |
else if (result.StatusCode == HttpStatusCode.Unauthorized) | |
{ | |
throw new UnauthorizedAccessException("Your Session has expired."); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment