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
- object
- RetryableHttpErrorHandler
- HttpError429Handler
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
statusCodeHttpStatusCode- The HTTP status code to evaluate.
Returns
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
ctxHttpResponseErrorContext- The context containing information about the HTTP response.
retryTimeNullable<DateTimeOffset>- The suggested retry time, if any.
Returns
- IHttpBackoffProvider
- An IHttpBackoffProvider representing the default backoff strategy.
Exceptions
- ArgumentNullException
- Thrown if
ctxisnull.
GetSuggestedRetryTime(HttpResponseErrorContext)
Extracts the suggested retry time from the HTTP response's header, if present.
protected override Nullable<DateTimeOffset> GetSuggestedRetryTime(HttpResponseErrorContext ctx)Parameters
ctxHttpResponseErrorContext- The context containing information about the HTTP response.
Returns
- Nullable<DateTimeOffset>
- The suggested DateTimeOffset to retry the request, or
nullif the header is not present.
Exceptions
- ArgumentNullException
- Thrown if
ctxisnull.
