Skip to content

Error class

Namespace: Vitreous
Assembly: Vitreous.dll

Represents a strongly-typed error produced by a command or query handler.

public sealed record Error : IEquatable<Error>

object ← Error

IEquatable<Error>

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()

Error(string, string, IReadOnlyDictionary<string, object?>?)

Section titled “ Error(string, string, IReadOnlyDictionary<string, object?>?)”

Represents a strongly-typed error produced by a command or query handler.

public Error(string Code, string Message, IReadOnlyDictionary<string, object?>? Extensions = null)

Code string

A short machine-readable error code (e.g. “NOT_FOUND”, “VALIDATION”).

Message string

A human-readable description of the error.

Extensions IReadOnlyDictionary<string, object?>?

Optional metadata — field violations, correlation IDs, etc.

A short machine-readable error code (e.g. “NOT_FOUND”, “VALIDATION”).

public string Code { get; init; }

string

The exception that caused this error, when one was supplied to Internal. Kept for logging and diagnostics only: it is never serialized, so exception details cannot leak to API clients through a serialized Error.

[JsonIgnore]
public Exception? Exception { get; init; }

Exception?

Optional metadata — field violations, correlation IDs, etc.

public IReadOnlyDictionary<string, object?>? Extensions { get; init; }

IReadOnlyDictionary<string, object?>?

A human-readable description of the error.

public string Message { get; init; }

string

The error reported by an uninitialized (default) Result or Result<T>, which is a failure that was never given an error.

public static Error Uninitialized { get; }

Error

Creates a “conflict” error (e.g. duplicate resource).

public static Error Conflict(string message, string? code = null)

message string

code string?

Error

Custom(string, string, IReadOnlyDictionary<string, object?>?)

Section titled “ Custom(string, string, IReadOnlyDictionary<string, object?>?)”

Creates a custom error with any code, message, and optional extensions.

public static Error Custom(string code, string message, IReadOnlyDictionary<string, object?>? extensions = null)

code string

message string

extensions IReadOnlyDictionary<string, object?>?

Error

Creates an “internal” error, optionally wrapping an exception.

public static Error Internal(string message, Exception? exception = null, string? code = null)

message string

exception Exception?

code string?

Error

The exception is available on Exception (with its stack trace) but is not serialized. Only its type name is added to Extensions as exceptionType; the exception message is deliberately left out because it often contains internal details that should not reach clients.

Creates a “not found” error.

public static Error NotFound(string message, string? code = null)

message string

code string?

Error

Returns a string that represents the current object.

public override string ToString()

string

A string that represents the current object.

Creates an “unauthorized” error.

public static Error Unauthorized(string message, string? code = null)

message string

code string?

Error

Validation(string, IReadOnlyDictionary<string, string[]>?, string?)

Section titled “ Validation(string, IReadOnlyDictionary<string, string[]>?, string?)”

Creates a validation error, optionally with per-field failures.

public static Error Validation(string message, IReadOnlyDictionary<string, string[]>? failures = null, string? code = null)

message string

failures IReadOnlyDictionary<string, string[]>?

code string?

Error