I have set up my Xamarin core project with a lot of the tips I read from here.
I have a simple service that I'm using to see if an entered url for a server is valid: IValidateUrlService
I'm trying to use the Polly library to do something like this:
var request = new PingUrlRequest();
var validateUrlTask = apiService.UserInitiated.ValidateUrl(request);
var response = await Policy
.Handle<ApiException>()
.RetryAsync(retryCount: 5)
.ExecuteAsync(async () =>
await validateUrlTask);
reachable = HandleServerResponse(response);
This works fine unless I get an Exception. For instance, when I was getting an ApiException on one server I was testing against; the above code did not absorb the error! It just threw the exception and crashed the program. I could only get the code to work properly by doing this:
try
{
var request = new PingUrlRequest();
var validateUrlTask = apiService.UserInitiated.ValidateUrl(request);
var response = await Policy
.Handle<ApiException>()
.RetryAsync(retryCount: 5)
.ExecuteAsync(async () =>
await validateUrlTask);
reachable = HandleServerResponse(response);
}
catch (ApiException e)
{
Mvx.Trace(e.StackTrace);
}
But that doesn't feel correct... What's the point of having the Handle parameter up top if it doesn't do anything? I have to be implementing this wrong! Any suggestions?