Enter a Catch Method in WaitAndRetryAsync

If you have tried the third time and it is not a success. Then you want to use another method.
I would like to to prevent displaying a error message webpage.

is it possible to enter a method that is similiar as catch method in WaitAndRetryAsync?

RetryPolicy<HttpResponseMesssage> httpWaitAndRetryPolicy = Policy
    .HandleResult<HttpResponseMessage>(r => !r.IsSuccessStatusCode)
        (3, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2. retryAttempt)/2));

Thank you!


You can use ExecuteAsync on your policy and then use ContinueWith to handle final response like this:

     (3, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt) / 2))
 .ExecuteAsync(() =>
     //do stuff that you want retry

 }).ContinueWith(x =>
     if (x.Exception != null)
         //means exception raised during execute and handle it

     // return your HttpResponseMessage

Leave a Reply

Your email address will not be published. Required fields are marked *