IHttpErrorHandler Interface

Namespace
Kampute.HttpClient.Interfaces
Assembly
  • Kampute.HttpClient.dll

Definition

Defines a handler that decides whether to retry a request after an error response.
public interface IHttpErrorHandler
Implemented by

Remarks

When a request receives an error response, HttpRestClient asks the handlers in HttpRestClient.ErrorHandlers whose CanHandle(HttpStatusCode) accepts the status code, in order, until one of them returns a request to retry. If none does, the error is thrown as an HttpResponseException. A handler can retry a clone of the failed request or a request it builds, for example one with new credentials after a '401 Unauthorized' response.

A handler is shared by all the requests of the clients it is added to, so implementations must be thread-safe.

Methods

CanHandle(HttpStatusCode)

Determines whether the handler is capable of handling the provided HTTP status code.
bool CanHandle(HttpStatusCode statusCode)

Parameters

statusCode HttpStatusCode
The HTTP status code to evaluate.

Returns

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

DecideOnRetryAsync(HttpResponseErrorContext, CancellationToken)

Decides whether to retry a request after an error response.
Task<HttpErrorHandlerResult> DecideOnRetryAsync(HttpResponseErrorContext ctx, CancellationToken cancellationToken)

Parameters

ctx HttpResponseErrorContext
The context containing information about the HTTP response that indicates a failure.
cancellationToken CancellationToken
A token for canceling the operation.

Returns

Task<HttpErrorHandlerResult>
A task that resolves to HttpErrorHandlerResult.Retry(HttpRequestMessage) with the request to send, or to HttpErrorHandlerResult.NoRetry to let the next handler decide.

Exceptions

ArgumentNullException
Thrown if ctx is null.

See Also