Class Error
- Namespace
- Compendium.Core.Results
- Assembly
- Compendium.Core.dll
Represents an error that occurred during operation execution. Provides structured error information with code, message, and optional details.
public sealed class Error : ValueObject, IEquatable<ValueObject>
- Inheritance
-
Error
- Implements
- Inherited Members
Constructors
Error(string, string, ErrorType, IReadOnlyDictionary<string, object>?)
Initializes a new instance of the Error class.
public Error(string code, string message, ErrorType type, IReadOnlyDictionary<string, object>? metadata = null)
Parameters
codestringThe error code.
messagestringThe error message.
typeErrorTypeThe error type.
metadataIReadOnlyDictionary<string, object>Optional metadata associated with the error.
Fields
None
Represents no error (success state).
public static readonly Error None
Field Value
NullValue
Represents a null value error.
public static readonly Error NullValue
Field Value
Properties
Code
Gets the error code that uniquely identifies the error type.
public string Code { get; }
Property Value
Message
Gets the human-readable error message.
public string Message { get; }
Property Value
Metadata
Gets additional metadata associated with the error.
public IReadOnlyDictionary<string, object> Metadata { get; }
Property Value
Type
Gets the error type classification.
public ErrorType Type { get; }
Property Value
Methods
Conflict(string, string, IReadOnlyDictionary<string, object>?)
Creates a conflict error.
public static Error Conflict(string code, string message, IReadOnlyDictionary<string, object>? metadata = null)
Parameters
codestringThe error code.
messagestringThe error message.
metadataIReadOnlyDictionary<string, object>Optional metadata.
Returns
- Error
A new conflict error.
Failure(string, string, IReadOnlyDictionary<string, object>?)
Creates a failure error.
public static Error Failure(string code, string message, IReadOnlyDictionary<string, object>? metadata = null)
Parameters
codestringThe error code.
messagestringThe error message.
metadataIReadOnlyDictionary<string, object>Optional metadata.
Returns
- Error
A new failure error.
Forbidden(string, string, IReadOnlyDictionary<string, object>?)
Creates a forbidden error.
public static Error Forbidden(string code, string message, IReadOnlyDictionary<string, object>? metadata = null)
Parameters
codestringThe error code.
messagestringThe error message.
metadataIReadOnlyDictionary<string, object>Optional metadata.
Returns
- Error
A new forbidden error.
GetEqualityComponents()
Gets the equality components that define the value object's identity.
protected override IEnumerable<object?> GetEqualityComponents()
Returns
- IEnumerable<object>
An enumerable of objects that participate in equality comparison.
NotFound(string, string, IReadOnlyDictionary<string, object>?)
Creates a not found error.
public static Error NotFound(string code, string message, IReadOnlyDictionary<string, object>? metadata = null)
Parameters
codestringThe error code.
messagestringThe error message.
metadataIReadOnlyDictionary<string, object>Optional metadata.
Returns
- Error
A new not found error.
ToString()
Returns a string representation of the error.
public override string ToString()
Returns
- string
A string that represents the current error.
TooManyRequests(string, string, IReadOnlyDictionary<string, object>?)
Creates a too many requests error.
public static Error TooManyRequests(string code, string message, IReadOnlyDictionary<string, object>? metadata = null)
Parameters
codestringThe error code.
messagestringThe error message.
metadataIReadOnlyDictionary<string, object>Optional metadata.
Returns
- Error
A new too many requests error.
Unauthorized(string, string, IReadOnlyDictionary<string, object>?)
Creates an unauthorized error.
public static Error Unauthorized(string code, string message, IReadOnlyDictionary<string, object>? metadata = null)
Parameters
codestringThe error code.
messagestringThe error message.
metadataIReadOnlyDictionary<string, object>Optional metadata.
Returns
- Error
A new unauthorized error.
Unavailable(string, string, IReadOnlyDictionary<string, object>?)
Creates an unavailable error.
public static Error Unavailable(string code, string message, IReadOnlyDictionary<string, object>? metadata = null)
Parameters
codestringThe error code.
messagestringThe error message.
metadataIReadOnlyDictionary<string, object>Optional metadata.
Returns
- Error
A new unavailable error.
Unexpected(string, string, IReadOnlyDictionary<string, object>?)
Creates an unexpected error.
public static Error Unexpected(string code, string message, IReadOnlyDictionary<string, object>? metadata = null)
Parameters
codestringThe error code.
messagestringThe error message.
metadataIReadOnlyDictionary<string, object>Optional metadata.
Returns
- Error
A new unexpected error.
Validation(string, string, IReadOnlyDictionary<string, object>?)
Creates a validation error.
public static Error Validation(string code, string message, IReadOnlyDictionary<string, object>? metadata = null)
Parameters
codestringThe error code.
messagestringThe error message.
metadataIReadOnlyDictionary<string, object>Optional metadata.
Returns
- Error
A new validation error.
Operators
implicit operator Error(string)
Implicitly converts a string to an Error.
public static implicit operator Error(string error)
Parameters
errorstringThe error message.