<PackageReference Include="Refit" Version="17.0.0" />

Refit.ApiException

Represents an error that occurred after a response was received from the server.
public string Content { get; set; }

Gets or sets the HTTP response content as a string.

public HttpContentHeaders ContentHeaders { get; protected set; }

Gets the HTTP response content headers as defined in RFC 2616.

public bool HasContent { get; }

Gets a value indicating whether the response has content.

public HttpResponseHeaders Headers { get; }

Gets the HTTP response headers.

public string ReasonPhrase { get; }

Gets the reason phrase which typically is sent by the server together with the status code.

public HttpStatusCode StatusCode { get; }

Gets the HTTP response status code.

protected ApiException(HttpRequestMessage message, HttpMethod httpMethod, string content, HttpStatusCode statusCode, string reasonPhrase, HttpResponseHeaders headers, RefitSettings refitSettings)

Initializes a new instance of the ApiException class.

protected ApiException(HttpRequestMessage message, HttpMethod httpMethod, string content, HttpStatusCode statusCode, string reasonPhrase, HttpResponseHeaders headers, RefitSettings refitSettings, Exception innerException)

Initializes a new instance of the ApiException class.

protected ApiException(string exceptionMessage, HttpRequestMessage message, HttpMethod httpMethod, string content, HttpStatusCode statusCode, string reasonPhrase, HttpResponseHeaders headers, RefitSettings refitSettings)

Initializes a new instance of the ApiException class.

protected ApiException(string exceptionMessage, HttpRequestMessage message, HttpMethod httpMethod, string content, HttpStatusCode statusCode, string reasonPhrase, HttpResponseHeaders headers, RefitSettings refitSettings, Exception innerException)

Initializes a new instance of the ApiException class.

public static Task<ApiException> Create(HttpRequestMessage message, HttpMethod httpMethod, HttpResponseMessage response, RefitSettings refitSettings)

Create an instance of ApiException.

public static Task<ApiException> Create(HttpRequestMessage message, HttpMethod httpMethod, HttpResponseMessage response, RefitSettings refitSettings, Exception innerException)

Create an instance of ApiException.

public static Task<ApiException> Create(string exceptionMessage, HttpRequestMessage message, HttpMethod httpMethod, HttpResponseMessage response, RefitSettings refitSettings)

Create an instance of ApiException with a custom exception message.

public static Task<ApiException> Create(string exceptionMessage, HttpRequestMessage message, HttpMethod httpMethod, HttpResponseMessage response, RefitSettings refitSettings, Exception innerException)

Create an instance of ApiException with a custom exception message.

public T GetContentAs<T>()

Synchronously deserializes the buffered response content as T. The content is already a string, so this can run inside an exception filter where awaiting is not allowed by the CLR.

public Task<T> GetContentAsAsync<T>()

Get the deserialized response content as nullable T.

public bool TryGetContentAs<T>(out T content)

Attempts to synchronously deserialize the buffered response content as T without throwing, making it usable from an exception filter: catch (ApiException ex) when (ex.TryGetContentAs<Error>(out var error)).