Skip to content

Commit 4367b44

Browse files
committed
Handle retry if RateLimiterRejectedException happens
1 parent b76b6ae commit 4367b44

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

projects/polly/rate-limiter-http-client/Program.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
{
2424
ShouldHandle = response =>
2525
{
26+
if (response.Outcome.Exception is RateLimiterRejectedException)
27+
return ValueTask.FromResult(true);
28+
2629
// retry when the status is not OK
2730
var result = response.Outcome.Result.StatusCode != HttpStatusCode.OK;
2831
return ValueTask.FromResult(result);
@@ -51,7 +54,10 @@
5154
return default;
5255
},
5356
BackoffType = DelayBackoffType.Constant
54-
}).Build();
57+
})
58+
59+
60+
.Build();
5561
});
5662

5763
var app = builder.Build();

projects/polly/rate-limiter-http-client/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
You can find the policy for rate limiting and retry at `Program.cs`.
44

55
- In this case, we only allow max 20 concurrent requests - anything beyond that will be queue maximum to 50. If it exceed this queue, `RateLimiterRejectedException` will be thrown.
6-
- We will retry maximum 3 times if the http request status is not `200`.
6+
- We will retry maximum 3 times if the http request status is not `200`.
7+
- We will retry also if `RateLimiterRejectedException` is thrown.

0 commit comments

Comments
 (0)