diff --git a/docs/strategies/retry.md b/docs/strategies/retry.md index 885cb65a649..4ebb9e64b02 100644 --- a/docs/strategies/retry.md +++ b/docs/strategies/retry.md @@ -474,18 +474,18 @@ Use collections and simple predicate functions: ```cs -ImmutableArray networkExceptions = new[] -{ +ImmutableArray networkExceptions = +[ typeof(SocketException), typeof(HttpRequestException), -}.ToImmutableArray(); +]; -ImmutableArray strategyExceptions = new[] -{ +ImmutableArray strategyExceptions = +[ typeof(TimeoutRejectedException), typeof(BrokenCircuitException), typeof(RateLimitRejectedException), -}.ToImmutableArray(); +]; ImmutableArray retryableExceptions = networkExceptions .Union(strategyExceptions) @@ -494,7 +494,8 @@ ImmutableArray retryableExceptions = networkExceptions var retry = new ResiliencePipelineBuilder() .AddRetry(new() { - ShouldHandle = ex => new ValueTask(retryableExceptions.Contains(ex.GetType())), + ShouldHandle = args + => ValueTask.FromResult(args.Outcome.Exception != null && retryableExceptions.Contains(args.Outcome.Exception.GetType())), MaxRetryAttempts = 3, }) .Build(); diff --git a/src/Snippets/Docs/Retry.cs b/src/Snippets/Docs/Retry.cs index e31ac2856bc..33c04f1cb60 100644 --- a/src/Snippets/Docs/Retry.cs +++ b/src/Snippets/Docs/Retry.cs @@ -174,18 +174,18 @@ public static void Pattern_OverusingBuilder() { #region retry-pattern-overusing-builder - ImmutableArray networkExceptions = new[] - { + ImmutableArray networkExceptions = + [ typeof(SocketException), typeof(HttpRequestException), - }.ToImmutableArray(); + ]; - ImmutableArray strategyExceptions = new[] - { + ImmutableArray strategyExceptions = + [ typeof(TimeoutRejectedException), typeof(BrokenCircuitException), typeof(RateLimitRejectedException), - }.ToImmutableArray(); + ]; ImmutableArray retryableExceptions = networkExceptions .Union(strategyExceptions) @@ -194,7 +194,9 @@ public static void Pattern_OverusingBuilder() var retry = new ResiliencePipelineBuilder() .AddRetry(new() { - ShouldHandle = ex => new ValueTask(retryableExceptions.Contains(ex.GetType())), + ShouldHandle = args + => ValueTask.FromResult(args.Outcome.Exception is not null + && retryableExceptions.Contains(args.Outcome.Exception.GetType())), MaxRetryAttempts = 3, }) .Build();