Class ApiException
- Namespace
- VpnHood.Net.Toolkit.ApiClients
- Assembly
- VpnHood.Net.Toolkit.dll
The exception that is thrown when an API call fails: its status code, its response and, when the response is an ApiError, the type of the exception the API threw.
public sealed class ApiException : Exception, ISerializable
- Inheritance
-
ApiException
- Implements
- Inherited Members
Constructors
ApiException(string, int, string?, IReadOnlyDictionary<string, IEnumerable<string>>?, Exception?)
Initializes a new instance of the ApiException class from a response. When the response is an ApiError, its message, type and data are the exception's; otherwise, the message carries the status and the response's first 512 characters.
public ApiException(string message, int statusCode, string? response, IReadOnlyDictionary<string, IEnumerable<string>>? headers, Exception? innerException)
Parameters
messagestringThe message.
statusCodeintThe HTTP status code.
responsestringThe response's body, or null.
headersIReadOnlyDictionary<string, IEnumerable<string>>The response's headers, or null for none.
innerExceptionExceptionThe exception that is the cause of this one, or null.
ApiException(ApiError)
Initializes a new instance of the ApiException class from an error, with status code 400.
public ApiException(ApiError apiError)
Parameters
apiErrorApiErrorThe error.
Properties
ExceptionTypeFullName
Gets the full name of the exception type the API threw, or null.
public string? ExceptionTypeFullName { get; }
Property Value
ExceptionTypeName
Gets the name of the exception type the API threw, or null when the response is no error.
public string? ExceptionTypeName { get; }
Property Value
Headers
Gets the response's headers.
public IReadOnlyDictionary<string, IEnumerable<string>> Headers { get; }
Property Value
Response
Gets the response's body, or null.
public string? Response { get; }
Property Value
StatusCode
Gets the HTTP status code; 400 for one made from an ApiError.
public int StatusCode { get; }
Property Value
Methods
Is<T>()
Determines whether the API threw an exception with the name of a type.
public bool Is<T>()
Returns
Type Parameters
TThe type.
ToApiError()
Makes the error the exception stands for, with the type the API threw, and the status code in its data as
InnerStatusCode.
public ApiError ToApiError()
Returns
- ApiError
The error.
ToString()
Returns the response's body, then the exception's own text.
public override string ToString()
Returns
- string
The text.