TransientHttpErrorHandler Class

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

Definition

Handles responses with a transient error status code by retrying the request after a delay.
public class TransientHttpErrorHandler : RetryableHttpErrorHandler
Inheritance

Remarks

If the first error response of a call that this handler handles has a Retry-After header, the request is retried once, at the time the header suggests; a repeated error response then reaches the caller. Without the header, the request is retried as the HttpRestClient.RetryPolicy of the client decides. RetryableHttpErrorHandler.OnRetryPolicy can choose another policy. If a suggested time is further away than RetryableHttpErrorHandler.MaxRetryDelay, which is five minutes by default, the request is not retried. See RetryableHttpErrorHandler for how the retries of a call are decided.

Constructors

TransientHttpErrorHandler()

Initializes a new instance of the TransientHttpErrorHandler class with default transient error status codes.
public TransientHttpErrorHandler()

Remarks

The default transient error status codes handled by this instance are:
  • 408–Request Timeout
  • 502–Bad Gateway
  • 503–Service Unavailable
  • 504–Gateway Timeout
  • 507–Insufficient Storage
  • 509–Bandwidth Limit Exceeded

TransientHttpErrorHandler(IEnumerable<HttpStatusCode>)

Initializes a new instance of the TransientHttpErrorHandler class with specified transient error status codes.
public TransientHttpErrorHandler(IEnumerable<HttpStatusCode> statusCodes)

Parameters

statusCodes IEnumerable<HttpStatusCode>
The collection of HTTP status codes that this handler will process as transient errors.

Exceptions

ArgumentNullException
Thrown if statusCodes is null.
ArgumentException
Thrown if statusCodes is empty.

Properties

HandledStatusCodes

Gets the collection of HTTP status codes that are considered transient errors and handled by this instance.
public IReadOnlyCollection<HttpStatusCode> HandledStatusCodes { get; }

Property Value

IReadOnlyCollection<HttpStatusCode>
A read-only collection of HttpStatusCode values that are treated as transient errors.

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.

See Also