I am trying to implement a retry policy that will retry if an exception is thrown.
Unfortunately I can't seem to get the signature for the onRetryAsync block right. The compiler says "Not all code paths return a value in lambda expression of type...."
The documentation suggests to return Task.CompletedTask but that's apparently not available to me in the current libraries I am forced to use.
var retryPolicy = Policy
.Handle<SigsThrottledException>(e => e.RetryAfterInSeconds > 0)
.WaitAndRetryAsync(
retryCount: 3,
sleepDurationProvider: (i, e, ctx) =>
{
var ste = (SigsThrottledException)e;
return TimeSpan.FromSeconds((double)ste.RetryAfterInSeconds);
},
onRetryAsync: (e, ts, i, ctx) =>
{
// Logging goes here
});
<....>
var response = await retryPolicy.Execute(async () =>
{
Uri substrateurl = new Uri("https://substrate.office.com/");
return await SIGSClient.Instance.PostAsync(client, substrateurl, new UserInfo(), "faketoken", new Signal(), Guid.NewGuid()).ConfigureAwait(false);
}
);