HttpResponseException Class

Namespace
Kampute.HttpClient
Assembly
  • Kampute.HttpClient.dll

Definition

The exception that is thrown when a request receives an error response that no error handler retries.
public class HttpResponseException : HttpRequestException
Inheritance

Constructors

HttpResponseException(HttpStatusCode)

Initializes a new instance of the HttpResponseException class with the specified status code.
public HttpResponseException(HttpStatusCode statusCode)

Parameters

statusCode HttpStatusCode
The HTTP status code associated with the exception.

HttpResponseException(HttpStatusCode, string)

Initializes a new instance of the HttpResponseException class with the specified status code and error message.
public HttpResponseException(HttpStatusCode statusCode, string message)

Parameters

statusCode HttpStatusCode
The HTTP status code associated with the exception.
message string
The error message that explains the reason for the exception.

HttpResponseException(HttpStatusCode, string, Exception)

Initializes a new instance of the HttpResponseException class with the specified status code, error message, and optional inner exception.
public HttpResponseException(HttpStatusCode statusCode, string message, Exception innerException)

Parameters

statusCode HttpStatusCode
The HTTP status code associated with the exception.
message string
The error message that explains the reason for the exception.
innerException Exception
The exception that is the cause of the current exception, or a null reference if no inner exception is specified.

Properties

Errors

Gets or sets the validation errors that the error response reports.
public IDictionary<string, string[]> Errors { get; set; }

Property Value

IDictionary<string, string[]>
The error messages of each invalid field, keyed by the field name, or null if there are none. An IHttpErrorResponse can set them from the error body.

ResponseMessage

Gets or sets the error response.
public HttpResponseMessage ResponseMessage { get; set; }

Property Value

HttpResponseMessage
The HttpResponseMessage of the error, or null if there is none.

Remarks

When HttpRestClient throws this exception, it has already disposed the response. The status code, reason phrase, response headers and request message remain readable, but reading the response content throws ObjectDisposedException.

To use a structured error body, set HttpRestClient.ResponseErrorType. The client then deserializes the error body before disposing the response, and exposes it through ResponseObject.

ResponseObject

Gets or sets the body of the error response, read as HttpRestClient.ResponseErrorType.
public object ResponseObject { get; set; }

Property Value

object
The object read from the error body, or null if HttpRestClient.ResponseErrorType is not set or the body could not be read.

StatusCode

Gets the HTTP status code associated with the exception.
public HttpStatusCode StatusCode { get; }

Property Value

HttpStatusCode
The HTTP status code associated with the exception.

Remarks

On .NET 10 and later, the inherited HttpRequestException.StatusCode has the same value, so exception filters on HttpRequestException can test the status code of an error response.

Methods

ToString()

Creates and returns a string representation of the current exception.
public override string ToString()

Returns

string
A string representation of the current exception.

Extension Methods

IsTransientNetworkError(this Exception)Determines whether an exception reports a network failure that a retry could overcome.