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
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
InnerMessage
Gets the inner exception's message, or null.
public string? InnerMessage { get; init; }
Property Value
Message
Gets the exception's message.
public required string Message { get; init; }
Property Value
TypeFullName
Gets the exception type's full name, or null.
public string? TypeFullName { get; init; }
Property Value
TypeName
Gets the exception type's name, such as NotExistsException.
public required string TypeName { get; init; }
Property Value
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
objobjectThe object to compare with the current object.
Returns
Equals(ApiError?)
Determines whether another error has the same names, messages and data.
public bool Equals(ApiError? other)
Parameters
otherApiErrorThe other error.
Returns
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
dataIDictionaryThe 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
dataIDictionaryThe exception's data.
Is<T>()
Determines whether the error's type has the name of a type.
public bool Is<T>()
Returns
Type Parameters
TThe type.
Parse(string)
Reads an error from its JSON, whose names match ignoring case.
public static ApiError Parse(string value)
Parameters
valuestringThe 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
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)