Given the following F# snippets
//User Code
.. code that can throw exceptions
"Success"
P1 policy
Policy
.Handle<CosmosException>(fun cx -> cx.StatusCode = HttpStatusCode.TooManyRequests)
.WaitAndRetryForever((fun _ cx _ -> (cx :?> CosmosException).RetryAfter.Value), (fun _ _ _ _ -> ()))
P2 policy
Policy<string>
.Handle<Exception>()
.Fallback("Failure")
P3 Policy
Policy<string>
.Handle<Exception>()
.Fallback(fun ex -> ex.Message)
Question #1 - How to combine P1 and P2?
Combine P1 and P2 in a policy P so that:
- if User Code succeeds, "Success" is returned to the caller
- if User Code throws CosmosException, P retries forever using the returned RetryAfter TimeSpan
- if User Code throws any other exception, "Failure" is returned to the caller
Question # 2 - How to write P3?
There doesn't seem to be a Fallback overload that allows to access the handled exception to use it when constructing the fallback return value
Final scope is to combine P1 and P3 to obtain a policy PFinal such that:
- if User Code succeeds, "Success" is returned to the caller
- if User Code throws CosmosException, PFinal retries forever using the returned RetryAfter TimeSpan
- if User Code throws any other exception, the handled exception message is returned to the caller