How do you set up a HandleResult<Result<T>> for any T?
See original GitHub issueI understand the requirements of having a strongly-typed HandleResult<T>
and only having one T
per policy, however I’m looking to do something with a library that returns a generic wrapped result, with the error message contained within the wrapper.
Example (from memory code, may contain issues):
interface IWebCallResult<T> {
public bool Success { get; }
public Error? Error { get; } // Will be filled in if there's an error.
public T? Data { get; } // Will be filled in if there's no error
}
I’d like to do something like:
TimoutPolicy = Policy
.HandleResult<IWebCallResult>(r => r.Success == false && (r.Error?.Message.Contains("timed out") ?? false))
.RetryAsync();
In other words, if the success is false and the error is timed out, then retry, otherwise fail. I have about 40 of these, so writing loads of boilerplate all saying exactly the same really feels DRY. Is there a way to handle this in Polly?
As it stands, I’ve got to do something like:
StringTimeoutPolicy = Policy
.HandleResult<IWebCallResult<string>>(r => r.Success == false && (r.Error?.Message.Contains("timed out") ?? false))
.RetryAsync();
ObjectTimeoutPolicy = Policy
.HandleResult<IWebCallResult<object>>(r => r.Success == false && (r.Error?.Message.Contains("timed out") ?? false))
.RetryAsync();
ThingTimeoutPolicy = Policy
.HandleResult<IWebCallResult<Thing>>(r => r.Success == false && (r.Error?.Message.Contains("timed out") ?? false))
.RetryAsync();
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
How to build a networking in Swift #195 - onmyway133/blog
Understanding HTML Form Encoding: URL Encoded and Multipart Forms ... .failure(error)) } public func handle(result: Result<T, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@LazerFX , @orty
This issue is addressed in v8 and will be closed in once v8 is released.
See the example: https://github.com/App-vNext/Polly/blob/v8-fixed-issues/src/Polly.Core.Tests/Issues/IssuesTests.HandleMultipleResults_898.cs
V8 Alpha released: https://www.nuget.org/packages/Polly.Core/
Samples: https://github.com/App-vNext/Polly/tree/main/samples