Skip to content

renanrolo/Gist.PollyWithFlurl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Gist.PollyWithFlurl

using Flurl;
using Flurl.Http;
using Polly;

Básic Flurl (without Polly)

IEnumerable<WeatherForecast> collection = await _baseUrl.AppendPathSegment("Success")
                                                        .GetJsonAsync<IEnumerable<WeatherForecast>>();

Using Flurl with Polly policy

var collection = await Policy.Handle<FlurlHttpException>(ShouldTryAgain)
                             .WaitAndRetryAsync(2, i =>
                             {
                                 Console.WriteLine($"Error on request. Try number '{i}'");
                                 return TimeSpan.FromSeconds(5);
                             })
                             .ExecuteAsync(() =>
                                 _baseUrl.AppendPathSegment("SuccessOnThirdTry")
                                    .GetJsonAsync<IEnumerable<WeatherForecast>>()
                             );
private static bool ShouldTryAgain(FlurlHttpException flurlHttpException)
{
    switch ((int)flurlHttpException.Call.Response.StatusCode)
    {
        case 500:
            return true;
        default:
            return false;
    }
}

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages