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

Remarks

If the first '429 Too Many Requests' response of a call suggests a retry time, in a Retry-After header or otherwise in a rate limit reset header such as x-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.

Methods

CanHandle(HttpStatusCode)

Determines whether this handler can process the specified HTTP status code.
public sealed override bool CanHandle(HttpStatusCode statusCode)

Parameters

statusCode HttpStatusCode
The HTTP status code to evaluate.

Returns

bool
true if the handler can process the status code; otherwise, false.

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

ctx HttpResponseErrorContext
The context of the first error response this handler handles during the call.
retryTime Nullable<DateTimeOffset>
The retry time the response suggests, or null if 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 ctx is null.

GetSuggestedRetryTime(HttpResponseErrorContext)

Reads the retry time that an error response suggests.
protected override Nullable<DateTimeOffset> GetSuggestedRetryTime(HttpResponseErrorContext ctx)

Parameters

ctx HttpResponseErrorContext
The context containing information about the HTTP response.

Returns

Nullable<DateTimeOffset>
The time the response suggests for the retry, or null if it suggests none. The base implementation reads the Retry-After header.

Exceptions

ArgumentNullException
Thrown if ctx is null.

See Also