HttpRequestErrorContext Class

Namespace
Kampute.HttpClient
Assembly
  • Kampute.HttpClient.dll

Definition

Describes a failed request to the code that decides whether to retry it: the client, the request, and the error.
public class HttpRequestErrorContext
Inheritance
Inherited by

Constructors

HttpRequestErrorContext(HttpRestClient, HttpRequestMessage, HttpRequestException, HttpRetryState)

Initializes a new instance of the HttpRequestErrorContext class.
public HttpRequestErrorContext(
	HttpRestClient client,
	HttpRequestMessage request,
	HttpRequestException error,
	HttpRetryState retryState)

Parameters

client HttpRestClient
The client that sent the request.
request HttpRequestMessage
The request that failed.
error HttpRequestException
The exception that describes the failure.
retryState HttpRetryState
The retry state of the call that sent the request, shared by all its attempts.

Exceptions

ArgumentNullException
Thrown if client, request, error or retryState is null.

Properties

Client

Gets the client that sent the request.
public HttpRestClient Client { get; }

Property Value

HttpRestClient
The HttpRestClient that sent the request.

Error

Gets the exception that describes the failure.
public HttpRequestException Error { get; }

Property Value

HttpRequestException
The HttpRequestException of the failure.

Request

Gets the request that failed.
public HttpRequestMessage Request { get; }

Property Value

HttpRequestMessage
The HttpRequestMessage that failed.

RetryState

Gets the retry state of the call that sent the request.
public HttpRetryState RetryState { get; }

Property Value

HttpRetryState
The HttpRetryState shared by all attempts of the call. ScheduleRetryAsync(object, Func<HttpRequestErrorContext, IRetrySession>, CancellationToken) keeps the retry session of each source in it.

Methods

ScheduleRetryAsync(object, Func<HttpRequestErrorContext, IRetrySession>, CancellationToken)

Waits as the retry session of the source decides, and returns a clone of the request to retry, or a decision not to retry.
public Task<HttpErrorHandlerResult> ScheduleRetryAsync(object source, Func<HttpRequestErrorContext, IRetrySession> sessionFactory, CancellationToken cancellationToken = default)

Parameters

source object
The component that handles this kind of failure and counts its retries, such as the HttpRestClient for connection failures or an IHttpErrorHandler for error responses.
sessionFactory Func<HttpRequestErrorContext, IRetrySession>
A function that creates the retry session of the source from this context, or returns null if the source does not retry.
cancellationToken CancellationToken optional
A token that can be used to cancel the operation.

Returns

Task<HttpErrorHandlerResult>
A task that resolves, after the wait, to a decision to retry with a clone of Request, or to HttpErrorHandlerResult.NoRetry.

Exceptions

ArgumentNullException
Thrown if source or sessionFactory is null.

Remarks

Each source has its own retry session for a call. The first time a source schedules a retry during a call, sessionFactory is called and the session it returns is kept in RetryState. Later failures from the same source during the same call reuse that session, so its retry limit and elapsed time cover all of them, whether the request to retry is a clone of the failed request or a request built by an error handler. Failures from another source use another session, so a call that fails in several ways can be retried more times in total than any one session allows.

If the request content cannot be sent again, the request is not retried and sessionFactory is not called.