I am trying to use Polly to handle status codes other than 200 OK so that it retries the API request.
However, I am struggling to understand how to Polly to swallow an exception and then execute a retry. This is what I currently have, but it is not syntactically correct:
var policy = Policy.HandleResult<HttpStatusCode>(r => r == HttpStatusCode.GatewayTimeout)
.Retry(5);
HttpWebResponse response;
policy.Execute(() =>
{
response = SendRequestToInitialiseApi(url);
});
In the execution, I need the response to also be assigned to a variable to be used elsewhere in the method.
The return type of the response is a 'HttpWebResponse' and when I get a '504' for instance, it throws an exception.
Any help/feedback would be appreciated.
Cheers