HttpError429Handler Class

Namespace
Kampute.HttpClient.ErrorHandlers
Assembly
  • Kampute.HttpClient.dll

Definition

Handles '429 Too Many Requests' HTTP responses by attempting to back off and retry the request according to a specified or default backoff strategy.
public class HttpError429Handler : RetryableHttpErrorHandler
Inheritance

Remarks

This handler provides a mechanism to respond to HTTP 429 errors by retrying the request after a delay. The delay duration and retry logic can be customized through the RetryableHttpErrorHandler.OnBackoffStrategy delegate. If the delegate is not provided, or does not specify a strategy, the handler will look for a rate limit reset header in the response. If the header is present, its value is used to determine the backoff duration. If the header is not present, no retries will be attempted.

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 implementation specifically handles the HTTP '429 Too Many Requests' status code.

GetDefaultStrategy(HttpResponseErrorContext, Nullable<DateTimeOffset>)

Provides the default backoff strategy when no custom strategy is specified.
protected override IHttpBackoffProvider GetDefaultStrategy(HttpResponseErrorContext ctx, Nullable<DateTimeOffset> retryTime)

Parameters

ctx HttpResponseErrorContext
The context containing information about the HTTP response.
retryTime Nullable<DateTimeOffset>
The suggested retry time, if any.

Returns

IHttpBackoffProvider
An IHttpBackoffProvider representing the default backoff strategy.

Exceptions

ArgumentNullException
Thrown if ctx is null.

GetSuggestedRetryTime(HttpResponseErrorContext)

Extracts the suggested retry time from the HTTP response's header, if present.
protected override Nullable<DateTimeOffset> GetSuggestedRetryTime(HttpResponseErrorContext ctx)

Parameters

ctx HttpResponseErrorContext
The context containing information about the HTTP response.

Returns

Nullable<DateTimeOffset>
The suggested DateTimeOffset to retry the request, or null if the header is not present.

Exceptions

ArgumentNullException
Thrown if ctx is null.

See Also