-
Notifications
You must be signed in to change notification settings - Fork 1
TooManyRequests
The Too Many Requests Retry handler/filter automatically waits for a specified interval and retrys the request when a 429 (Too Many Requests) response is received from the server.
A maximum wait interval can be specified, if the server specifies a retry after time that is greater than the wait interval then the 429 response is returned to the caller so it can decide how to proceed. Specify TimeSpan.Zero to indicate there is no maximum wait time. The maximum wait time is also used as a default if the server does not provide a retry after header.
A maximum number of retries can also be specified.
Conditional logic is NOT currently supported. All 429 responses will result in a wait & retry.
This sample configures an HTTP client instance to use the Service Unavailable Retry handler.
// Configure the http client
var handler = new TooManyRequestsRetryHandler(
new System.Net.Http.HttpClientHandler(),
3, // Max retry attempts
TimeSpan.FromSeconds(30) // Max wait interval per attempt
);
var client = new System.Net.Http.HttpClient(handler);
// Make a request that will be retried if a 429 response is received.
var result = await client.GetAsync("https://t.co/YJ9y1xD2be");