Table of Contents

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

message string

The message.

statusCode int

The HTTP status code.

response string

The response's body, or null.

headers IReadOnlyDictionary<string, IEnumerable<string>>

The response's headers, or null for none.

innerException Exception

The 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

apiError ApiError

The error.

Properties

ExceptionTypeFullName

Gets the full name of the exception type the API threw, or null.

public string? ExceptionTypeFullName { get; }

Property Value

string

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

string

Headers

Gets the response's headers.

public IReadOnlyDictionary<string, IEnumerable<string>> Headers { get; }

Property Value

IReadOnlyDictionary<string, IEnumerable<string>>

Response

Gets the response's body, or null.

public string? Response { get; }

Property Value

string

StatusCode

Gets the HTTP status code; 400 for one made from an ApiError.

public int StatusCode { get; }

Property Value

int

Methods

Is<T>()

Determines whether the API threw an exception with the name of a type.

public bool Is<T>()

Returns

bool

true if the names match; otherwise, false.

Type Parameters

T

The 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.