#region ========================================================================= USING ===================================================================================== using Lumina.Presentation.Web.Common.Enums.Primitives; #endregion namespace Lumina.Presentation.Web.Common.Primitives; /// /// Represents an error that can be implicitly converted to a Result. /// public abstract record Error { /// /// Gets the type of this error. /// public abstract ErrorType Type { get; } /// /// Gets the error code that uniquely identifies this error type. /// public abstract string Code { get; } /// /// Gets the human-readable description of the error. /// public abstract string Description { get; } /// /// Returns a string representation of the error. /// /// A formatted string containing the error code and description. public override string ToString() { return $"{Code}: {Description}"; } /// /// Creates a new NotFoundError. /// /// The error code, defaults to "General.NotFound" when null. /// The human-readable description of the error. /// A new NotFoundError instance. public static NotFoundError NotFound(string? code = null, string? description = null) { return new(code ?? "General.NotFound", description ?? "A 'Not Found' error has occurred."); } /// /// Creates a new InvalidOperationError. /// /// The error code, defaults to "General.InvalidOperation" when null. /// The human-readable description of the error. /// A new InvalidOperationError instance. public static InvalidOperationError InvalidOperation(string? code = null, string? description = null) { return new(code ?? "General.InvalidOperation", description ?? "An invalid operation error has occurred."); } /// /// Creates a new ForbiddenError. /// /// The error code, defaults to "General.Forbidden" when null. /// The human-readable description of the error. /// A new ForbiddenError instance. public static ForbiddenError Forbidden(string? code = null, string? description = null) { return new(code ?? "General.Forbidden", description ?? "A 'Forbidden' error has occurred."); } /// /// Creates a new FailureError. /// /// The error code, defaults to "General.Failure" when null. /// The human-readable description of the error. /// A new FailureError instance. public static FailureError Failure(string? code = null, string? description = null) { return new(code ?? "General.Failure", description ?? "A failure has occurred."); } /// /// Creates a new ValidationError. /// /// The error code, defaults to "General.Validation" when null. /// The human-readable description of the error. /// A new ValidationError instance. public static ValidationError Validation(string? code = null, string? description = null) { return new(code ?? "General.Validation", description ?? "A validation error has occurred."); } /// /// Creates a new ConflictError. /// /// The error code, defaults to "General.Conflict" when null. /// The human-readable description of the error. /// A new ConflictError instance. public static ConflictError Conflict(string? code = null, string? description = null) { return new(code ?? "General.Conflict", description ?? "A conflict error has occurred."); } /// /// Creates a new TimeoutError. /// /// The error code, defaults to "General.Timeout" when null. /// The human-readable description of the error. /// A new TimeoutError instance. public static TimeoutError Timeout(string? code = null, string? description = null) { return new(code ?? "General.Timeout", description ?? "The operation timed out."); } /// /// Creates a new UnauthorizedError. /// /// The error code, defaults to "General.Unauthorized" when null. /// The human-readable description of the error. /// A new UnauthorizedError instance. public static UnauthorizedError Unauthorized(string? code = null, string? description = null) { return new(code ?? "General.Unauthorized", description ?? "An 'Unauthorized' error has occurred."); } /// /// Creates a new UnexpectedError. /// /// The error code, defaults to "General.Unexpected" when null. /// The human-readable description of the error. /// A new UnexpectedError instance. public static UnexpectedError Unexpected(string? code = null, string? description = null) { return new(code ?? "General.Unexpected", description ?? "An unexpected error has occurred."); } /// /// Creates a new InternalError. /// /// The error code, defaults to "General.Internal" when null. /// The human-readable description of the error. /// A new InternalError instance. public static InternalError Internal(string? code = null, string? description = null) { return new(code ?? "General.Internal", description ?? "An internal error has occurred."); } /// /// Creates a new ResourceUnavailableError. /// /// The error code, defaults to "General.ResourceUnavailable" when null. /// The human-readable description of the error. /// A new ResourceUnavailableError instance. public static ResourceUnavailableError ResourceUnavailable(string? code = null, string? description = null) { return new(code ?? "General.ResourceUnavailable", description ?? "The required resource is currently unavailable."); } /// /// Creates a new NotImplementedError. /// /// The error code, defaults to "General.NotImplemented" when null. /// The human-readable description of the error. /// A new NotImplementedError instance. public static NotImplementedError NotImplemented(string? code = null, string? description = null) { return new(code ?? "General.NotImplemented", description ?? "The requested functionality is not implemented."); } }