IHttpErrorHandler Interface
- Namespace
- Kampute.HttpClient.Interfaces
- Assembly
- Kampute.HttpClient.dll
Definition
Defines a contract for handling HTTP error status codes and determining retry logic in HTTP requests.
public interface IHttpErrorHandlerRemarks
Methods
CanHandle(HttpStatusCode)
Determines whether the handler is capable of handling the provided HTTP status code.
bool CanHandle(HttpStatusCode statusCode)Parameters
statusCodeHttpStatusCode- The HTTP status code to evaluate.
Returns
DecideOnRetryAsync(HttpResponseErrorContext, CancellationToken)
Evaluates whether a failed request should be retried based on the error context.
Task<HttpErrorHandlerResult> DecideOnRetryAsync(HttpResponseErrorContext ctx, CancellationToken cancellationToken)Parameters
ctxHttpResponseErrorContext- The context containing information about the HTTP response that indicates a failure.
cancellationTokenCancellationToken- A token for canceling the operation.
Returns
- Task<HttpErrorHandlerResult>
- A task that resolves to an HttpErrorHandlerResult.
Exceptions
- ArgumentNullException
- Thrown if
ctxisnull.

This interface provides a mechanism to extend the retry logic of the HttpRestClient. By implementing this interface, consumers of the client can implement custom logic to evaluate failure responses and decide whether to attempt a retry.
Implementors can define their own strategies for handling specific HTTP error statuses, such as '401 Unauthorized' for re-authentication, '429 Too Many Requests' for rate limit handling, or '503 Service Unavailable' for backoff and retry. This flexible approach allows for sophisticated error handling and recovery mechanisms, tailored to the requirements of the application.
The implementations of IHttpErrorHandler should be thread-safe and reusable across multiple error handling operations to facilitate efficient processing of HTTP responses in a concurrent environment.