Table of Contents

Class ApiError

Namespace
VpnHood.Net.Toolkit.ApiClients
Assembly
VpnHood.Net.Toolkit.dll

Represents an exception as an API sends it: its type's names, its message, its data and its inner exception's message, as JSON a client turns back into an exception.

public class ApiError : ICloneable, IEquatable<ApiError>
Inheritance
ApiError
Implements
Inherited Members
Extension Methods

Fields

Flag

The data key that marks an exception made from an ApiError: IsApiError.

public const string Flag = "IsApiError"

Field Value

string

Properties

Data

Gets the exception's data, as text. The default is none, and JSON null reads as none.

[AllowNull]
public Dictionary<string, string?> Data { get; init; }

Property Value

Dictionary<string, string>

InnerMessage

Gets the inner exception's message, or null.

public string? InnerMessage { get; init; }

Property Value

string

Message

Gets the exception's message.

public required string Message { get; init; }

Property Value

string

TypeFullName

Gets the exception type's full name, or null.

public string? TypeFullName { get; init; }

Property Value

string

TypeName

Gets the exception type's name, such as NotExistsException.

public required string TypeName { get; init; }

Property Value

string

Methods

Clone()

Copies the error, with a data dictionary of its own.

public object Clone()

Returns

object

The copy.

Equals(object?)

Determines whether the specified object is equal to the current object.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current object.

Returns

bool

true if the specified object is equal to the current object; otherwise, false.

Equals(ApiError?)

Determines whether another error has the same names, messages and data.

public bool Equals(ApiError? other)

Parameters

other ApiError

The other error.

Returns

bool

true if they are the same; otherwise, false.

ExportData(IDictionary)

Adds the error's data, its type's names and Flag to an exception's data, keeping the keys it has.

public void ExportData(IDictionary data)

Parameters

data IDictionary

The exception's data.

GetHashCode()

Serves as the default hash function.

public override int GetHashCode()

Returns

int

A hash code for the current object.

ImportData(IDictionary)

Adds an exception's data to the error's, as text, keeping the keys it has, and adds Flag.

public void ImportData(IDictionary data)

Parameters

data IDictionary

The exception's data.

Is<T>()

Determines whether the error's type has the name of a type.

public bool Is<T>()

Returns

bool

true if the names match; otherwise, false.

Type Parameters

T

The type.

Parse(string)

Reads an error from its JSON, whose names match ignoring case.

public static ApiError Parse(string value)

Parameters

value string

The JSON.

Returns

ApiError

The error.

Exceptions

FormatException

The JSON is not an error with a type name and a message.

ToException()

Makes the exception the error stands for: one of the common types it names, such as OperationCanceledException, TimeoutException or NotExistsException, or else an ApiException, with the error's data and names in its Data.

public Exception ToException()

Returns

Exception

The exception.

ToJson(bool)

Writes the error as JSON.

public string ToJson(bool writeIndented = false)

Parameters

writeIndented bool

true to indent the JSON.

Returns

string

The JSON.

ToString()

Returns the error's names, messages and data on one line.

public override string ToString()

Returns

string

The text.

TryParse(string, out ApiError?)

Tries to read an error from its JSON, whose names match ignoring case.

public static bool TryParse(string value, out ApiError? apiError)

Parameters

value string

The JSON.

apiError ApiError

The error, when read; otherwise, null.

Returns

bool

true if the JSON is an error with a type name and a message; otherwise, false.