Polly icon indicating copy to clipboard operation
Polly copied to clipboard

WaitAndRetryAsync - on Retry Delegate - question.

Open dazinator opened this issue 2 years ago • 1 comments

Summary: What are you wanting to achieve?

I have a question, i'm using http client factory and I would like to handle transient errors, but would also like to log a message whenever one occurs.

I can see the following api allows a delegate to be supplied onRetry:

 .AddTransientHttpErrorPolicy((builder) => builder.WaitAndRetryAsync(new[]
                    {
                        TimeSpan.FromSeconds(1),
                        TimeSpan.FromSeconds(30),
                        TimeSpan.FromMinutes(2)
                    },  onRetry ));

My question is, if this delegate is supplied, is it now entirely down to you to retry the http call in your onRetry delegate? Or is this delegate a supplement to the existing polly http retry call, so you don't have to worry about attempting the http request yourself, and can just focus on additional tasks like logging on such in there?

dazinator avatar Nov 18 '21 22:11 dazinator

Sorry for the delayed reply - yes, onRetry is for you to do custom things when a retry happens, such as logging a message or emitting a metric. It's isn't for you to re-implement the retrying yourself.

martincostello avatar Jan 24 '22 15:01 martincostello