HttpError429Handler Class
- Namespace
- Kampute.HttpClient.ErrorHandlers
- Assembly
- Kampute.HttpClient.dll
Definition
Handles '429 Too Many Requests' responses by retrying the request when the server allows it.
public class HttpError429Handler : RetryableHttpErrorHandler- Inheritance
- object
- RetryableHttpErrorHandler
- HttpError429Handler
Remarks
Methods
CanHandle(HttpStatusCode)
Determines whether this handler can process the specified HTTP status code.
public sealed override bool CanHandle(HttpStatusCode statusCode)Parameters
statusCodeHttpStatusCode- The HTTP status code to evaluate.
Returns
Remarks
This handler handles the '429 Too Many Requests' status code only.
GetDefaultPolicy(HttpResponseErrorContext, Nullable<DateTimeOffset>)
Returns the retry policy of this handler for a call when RetryableHttpErrorHandler.OnRetryPolicy provides none.
protected override IHttpRetryPolicy GetDefaultPolicy(HttpResponseErrorContext ctx, Nullable<DateTimeOffset> retryTime)Parameters
ctxHttpResponseErrorContext- The context of the first error response this handler handles during the call.
retryTimeNullable<DateTimeOffset>- The retry time the response suggests, or
nullif it suggests none.
Returns
- IHttpRetryPolicy
- The base implementation returns a policy that retries once, at
retryTime, if the response suggests a retry time, and the HttpRestClient.RetryPolicy of the client otherwise.
Exceptions
- ArgumentNullException
- Thrown if
ctxisnull.
GetSuggestedRetryTime(HttpResponseErrorContext)
Reads the retry time that an error response suggests.
protected override Nullable<DateTimeOffset> GetSuggestedRetryTime(HttpResponseErrorContext ctx)Parameters
ctxHttpResponseErrorContext- The context containing information about the HTTP response.
Returns
- Nullable<DateTimeOffset>
- The time the response suggests for the retry, or
nullif it suggests none. The base implementation reads theRetry-Afterheader.
Exceptions
- ArgumentNullException
- Thrown if
ctxisnull.

Retry-Afterheader or otherwise in a rate limit reset header such asx-ratelimit-reset, the request is retried once, at that time; a repeated 429 response then reaches the caller. Without a suggested time, the request is not retried. RetryableHttpErrorHandler.OnRetryPolicy can choose another policy. If a suggested time is further away than RetryableHttpErrorHandler.MaxRetryDelay, which is five minutes by default, the request is not retried. See RetryableHttpErrorHandler for how the retries of a call are decided, and TryExtractRateLimitResetTime(this HttpResponseHeaders, out Nullable<DateTimeOffset>) for the headers that are read.