Comments (2)
Looking at your code, my guess is that the operation fails 6 times in a row, so you see the exception bubbling up from the sixth attempt because you're configured to allow for 5.
If you never want to see an exception thrown, you would also need to include a fallback policy to provide a value to use instead. Though for your use case of getting an access token, I assume there's nothing you can really provide as a fallback in that case.
from polly.
Thanks for the pointer. That WAS the issue. I updated my code like below and it made it work.
private static AuthenticationResult GetNewToken(string token, string refreshToken, out API_AuthenticationResult API_result)
{
var fallBackOption = new FallbackStrategyOptions<API_Response<API_AuthenticationResult>>
{
ShouldHandle = new PredicateBuilder<API_Response<API_AuthenticationResult>>()
.Handle<Exception>(),
FallbackAction = args =>
{
return Outcome.FromResultAsValueTask(new API_Response<API_AuthenticationResult>()
{
Code = ResponseCode.UserNotExist405,
Message = "Please login again."
});
},
OnFallback = args =>
{
return default;
}
};
var retryOptions = new RetryStrategyOptions<API_Response<API_AuthenticationResult>>
{
Delay = TimeSpan.FromSeconds(1),
MaxRetryAttempts = 5,
ShouldHandle = new PredicateBuilder<API_Response<API_AuthenticationResult>>()
.Handle<Exception>()
};
var pipelineBuilder = new ResiliencePipelineBuilder<API_Response<API_AuthenticationResult>>();
pipelineBuilder.AddFallback<API_Response<API_AuthenticationResult>>(fallBackOption);
pipelineBuilder.AddRetry<API_Response<API_AuthenticationResult>>(retryOptions);
var pipeline = pipelineBuilder.Build();
var result = pipeline.Execute(() =>
{
var body = new
{
Token = token,
RefreshToken = refreshToken
};
var res = DataAccess.RestAPI_GetData<API_AuthenticationResult>(CreateRibbon.Application.AppSettings.ApiBaseAddress,
API_Endpoints.RefreshToken,
null,
body: body);
if (res == null)
{
throw new Exception("API response is null");
}
if (res != null && res.Code != ResponseCode.Success201)
{
throw new Exception(res.Message);
}
return res;
});
return ProcessAuthentication(result, out API_result);
}```
from polly.
Related Issues (20)
- [Feature request]: Add ConfigureResiliencePipelineRegistry to IServiceCollection HOT 4
- [Question]: Customize telemetry event severity? HOT 10
- [Bug]: Retry Startegy stops retrying unexpectedly
- [Feature request]: Make 'PipelineDisposed' event available on ResiliencePipelineProvider HOT 1
- [Question]: Polly 8.2.0 Why Timeout not effective? HOT 9
- [Question]: Replacing ResiliencePipelineProvider with keyed services HOT 8
- [Bug]: ResiliencePipelineBuilder AddCircuitBreaker grows stacktrace uncontrollably HOT 11
- [Feature request]: Relax validation of TimeoutStrategyOptions.Timeout HOT 4
- how to use it for retry but not fault situation? HOT 10
- [Question]: Circuit Breaker: Using BreakDurationGenerator to implement exponential backoff of open to half-open state HOT 1
- [Question]: Polly v8.2.0 how to use AddRetry and AddFallback methods HOT 16
- Simmy API Review and Feedback HOT 32
- [Feature request]: Adding Polly.Telemetry event for being out of retries HOT 4
- [Question]: Is Polly compatible with Unity ? HOT 2
- [Question]: HOT 1
- [Question]: Complex Pipeline Keys documentation example not working as expected HOT 2
- [Question]: Migration from HOT 4
- [Bug]: Retry doesn't happen with FakeTimerProvider.Advance HOT 5
- [Feature request]: Integrate / add support for Lunar Proxy (backend resilience strategy) HOT 3
- [Question]: How can I suppress Execution Attempt log when using Polly V8 ResiliencePipelineBuilder? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from polly.