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>Inheritance
Section titled “Inheritance”Implements
Section titled “Implements”Inherited Members
Section titled “Inherited Members”object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()
Constructors
Section titled “Constructors”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)Parameters
Section titled “Parameters”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.
Properties
Section titled “Properties”A short machine-readable error code (e.g. “NOT_FOUND”, “VALIDATION”).
public string Code { get; init; }Property Value
Section titled “Property Value”Exception
Section titled “ Exception”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; }Property Value
Section titled “Property Value”Extensions
Section titled “ Extensions”Optional metadata — field violations, correlation IDs, etc.
public IReadOnlyDictionary<string, object?>? Extensions { get; init; }Property Value
Section titled “Property Value”IReadOnlyDictionary<string, object?>?
Message
Section titled “ Message”A human-readable description of the error.
public string Message { get; init; }Property Value
Section titled “Property Value”Uninitialized
Section titled “ Uninitialized”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; }Property Value
Section titled “Property Value”Methods
Section titled “Methods”Conflict(string, string?)
Section titled “ Conflict(string, string?)”Creates a “conflict” error (e.g. duplicate resource).
public static Error Conflict(string message, string? code = null)Parameters
Section titled “Parameters”message string
code string?
Returns
Section titled “Returns”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)Parameters
Section titled “Parameters”code string
message string
extensions IReadOnlyDictionary<string, object?>?
Returns
Section titled “Returns”Internal(string, Exception?, string?)
Section titled “ Internal(string, Exception?, string?)”Creates an “internal” error, optionally wrapping an exception.
public static Error Internal(string message, Exception? exception = null, string? code = null)Parameters
Section titled “Parameters”message string
exception Exception?
code string?
Returns
Section titled “Returns”Remarks
Section titled “Remarks”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.
NotFound(string, string?)
Section titled “ NotFound(string, string?)”Creates a “not found” error.
public static Error NotFound(string message, string? code = null)Parameters
Section titled “Parameters”message string
code string?
Returns
Section titled “Returns”ToString()
Section titled “ ToString()”Returns a string that represents the current object.
public override string ToString()Returns
Section titled “Returns”A string that represents the current object.
Unauthorized(string, string?)
Section titled “ Unauthorized(string, string?)”Creates an “unauthorized” error.
public static Error Unauthorized(string message, string? code = null)Parameters
Section titled “Parameters”message string
code string?
Returns
Section titled “Returns”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)Parameters
Section titled “Parameters”message string
failures IReadOnlyDictionary<string, string[]>?
code string?