diff --git a/src/Lumina.Presentation.Web/Common/Enums/Primitives/ErrorType.cs b/src/Lumina.Presentation.Web/Common/Enums/Primitives/ErrorType.cs new file mode 100644 index 00000000..a7d3b44e --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Enums/Primitives/ErrorType.cs @@ -0,0 +1,42 @@ +namespace Lumina.Presentation.Web.Common.Enums.Primitives; + +/// +/// Enumeration for the type of an error. +/// +public enum ErrorType +{ + /// + /// Represents a generic failure. + /// + Failure, + + /// + /// Represents an unexpected error. + /// + Unexpected, + + /// + /// Represents a validation error. + /// + Validation, + + /// + /// Represents a conflict error. + /// + Conflict, + + /// + /// Represents a not found error. + /// + NotFound, + + /// + /// Represents an unauthorized error. + /// + Unauthorized, + + /// + /// Represents a forbidden error. + /// + Forbidden, +} diff --git a/src/Lumina.Presentation.Web/Common/Primitives/ConflictError.cs b/src/Lumina.Presentation.Web/Common/Primitives/ConflictError.cs new file mode 100644 index 00000000..3aa3f659 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Primitives/ConflictError.cs @@ -0,0 +1,28 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Enums.Primitives; +#endregion + +namespace Lumina.Presentation.Web.Common.Primitives; + +/// +/// Error representing that the operation could not be completed due to a conflict with the current state. +/// +/// The error code that uniquely identifies this error type. +/// The human-readable description of the error. +public record ConflictError(string Code, string Description) : Error +{ + /// + /// Gets the type of this error. + /// + public override ErrorType Type => ErrorType.Conflict; + + /// + /// Gets the error code that uniquely identifies this error type. + /// + public override string Code { get; } = Code; + + /// + /// Gets the human-readable description of the error. + /// + public override string Description { get; } = Description; +} diff --git a/src/Lumina.Presentation.Web/Common/Primitives/Created.cs b/src/Lumina.Presentation.Web/Common/Primitives/Created.cs new file mode 100644 index 00000000..2d06e289 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Primitives/Created.cs @@ -0,0 +1,6 @@ +namespace Lumina.Presentation.Web.Common.Primitives; + +/// +/// Represents a successful creation operation result. +/// +public readonly record struct Created; diff --git a/src/Lumina.Presentation.Web/Common/Primitives/Deleted.cs b/src/Lumina.Presentation.Web/Common/Primitives/Deleted.cs new file mode 100644 index 00000000..b6cea402 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Primitives/Deleted.cs @@ -0,0 +1,6 @@ +namespace Lumina.Presentation.Web.Common.Primitives; + +/// +/// Represents a successful deletion operation result. +/// +public readonly record struct Deleted; diff --git a/src/Lumina.Presentation.Web/Common/Primitives/Error.cs b/src/Lumina.Presentation.Web/Common/Primitives/Error.cs new file mode 100644 index 00000000..46e04df8 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Primitives/Error.cs @@ -0,0 +1,167 @@ +#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."); + } +} diff --git a/src/Lumina.Presentation.Web/Common/Primitives/FailureError.cs b/src/Lumina.Presentation.Web/Common/Primitives/FailureError.cs new file mode 100644 index 00000000..ab3f67e0 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Primitives/FailureError.cs @@ -0,0 +1,28 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Enums.Primitives; +#endregion + +namespace Lumina.Presentation.Web.Common.Primitives; + +/// +/// Error representing that some operation failing. +/// +/// The error code that uniquely identifies this error type. +/// The human-readable description of the error. +public record FailureError(string Code, string Description) : Error +{ + /// + /// Gets the type of this error. + /// + public override ErrorType Type => ErrorType.Failure; + + /// + /// Gets the error code that uniquely identifies this error type. + /// + public override string Code { get; } = Code; + + /// + /// Gets the human-readable description of the error. + /// + public override string Description { get; } = Description; +} diff --git a/src/Lumina.Presentation.Web/Common/Primitives/ForbiddenError.cs b/src/Lumina.Presentation.Web/Common/Primitives/ForbiddenError.cs new file mode 100644 index 00000000..d7498e08 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Primitives/ForbiddenError.cs @@ -0,0 +1,28 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Enums.Primitives; +#endregion + +namespace Lumina.Presentation.Web.Common.Primitives; + +/// +/// Error representing that the operation is not allowed due to insufficient permissions or restrictions. +/// +/// The error code that uniquely identifies this error type. +/// The human-readable description of the error. +public record ForbiddenError(string Code, string Description) : Error +{ + /// + /// Gets the type of this error. + /// + public override ErrorType Type => ErrorType.Forbidden; + + /// + /// Gets the error code that uniquely identifies this error type. + /// + public override string Code { get; } = Code; + + /// + /// Gets the human-readable description of the error. + /// + public override string Description { get; } = Description; +} diff --git a/src/Lumina.Presentation.Web/Common/Primitives/InternalError.cs b/src/Lumina.Presentation.Web/Common/Primitives/InternalError.cs new file mode 100644 index 00000000..e83985ea --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Primitives/InternalError.cs @@ -0,0 +1,28 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Enums.Primitives; +#endregion + +namespace Lumina.Presentation.Web.Common.Primitives; + +/// +/// Error representing that an unexpected internal error occurred. +/// +/// The error code that uniquely identifies this error type. +/// The human-readable description of the error. +public record InternalError(string Code, string Description) : Error +{ + /// + /// Gets the type of this error. + /// + public override ErrorType Type => ErrorType.Unexpected; + + /// + /// Gets the error code that uniquely identifies this error type. + /// + public override string Code { get; } = Code; + + /// + /// Gets the human-readable description of the error. + /// + public override string Description { get; } = Description; +} diff --git a/src/Lumina.Presentation.Web/Common/Primitives/InvalidOperationError.cs b/src/Lumina.Presentation.Web/Common/Primitives/InvalidOperationError.cs new file mode 100644 index 00000000..51a37a0b --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Primitives/InvalidOperationError.cs @@ -0,0 +1,28 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Enums.Primitives; +#endregion + +namespace Lumina.Presentation.Web.Common.Primitives; + +/// +/// Error representing that the operation is invalid in the current state or context. +/// +/// The error code that uniquely identifies this error type. +/// The human-readable description of the error. +public record InvalidOperationError(string Code, string Description) : Error +{ + /// + /// Gets the type of this error. + /// + public override ErrorType Type => ErrorType.Unexpected; + + /// + /// Gets the error code that uniquely identifies this error type. + /// + public override string Code { get; } = Code; + + /// + /// Gets the human-readable description of the error. + /// + public override string Description { get; } = Description; +} diff --git a/src/Lumina.Presentation.Web/Common/Primitives/NotFoundError.cs b/src/Lumina.Presentation.Web/Common/Primitives/NotFoundError.cs new file mode 100644 index 00000000..7fd35a0f --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Primitives/NotFoundError.cs @@ -0,0 +1,28 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Enums.Primitives; +#endregion + +namespace Lumina.Presentation.Web.Common.Primitives; + +/// +/// Error representing that the requested resource or entity was not found. +/// +/// The error code that uniquely identifies this error type. +/// The human-readable description of the error. +public record NotFoundError(string Code, string Description) : Error +{ + /// + /// Gets the type of this error. + /// + public override ErrorType Type => ErrorType.NotFound; + + /// + /// Gets the error code that uniquely identifies this error type. + /// + public override string Code { get; } = Code; + + /// + /// Gets the human-readable description of the error. + /// + public override string Description { get; } = Description; +} diff --git a/src/Lumina.Presentation.Web/Common/Primitives/NotImplementedError.cs b/src/Lumina.Presentation.Web/Common/Primitives/NotImplementedError.cs new file mode 100644 index 00000000..dc323507 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Primitives/NotImplementedError.cs @@ -0,0 +1,28 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Enums.Primitives; +#endregion + +namespace Lumina.Presentation.Web.Common.Primitives; + +/// +/// Error representing that the requested functionality is not implemented. +/// +/// The error code that uniquely identifies this error type. +/// The human-readable description of the error. +public record NotImplementedError(string Code, string Description) : Error +{ + /// + /// Gets the type of this error. + /// + public override ErrorType Type => ErrorType.Unexpected; + + /// + /// Gets the error code that uniquely identifies this error type. + /// + public override string Code { get; } = Code; + + /// + /// Gets the human-readable description of the error. + /// + public override string Description { get; } = Description; +} diff --git a/src/Lumina.Presentation.Web/Common/Primitives/ResourceUnavailableError.cs b/src/Lumina.Presentation.Web/Common/Primitives/ResourceUnavailableError.cs new file mode 100644 index 00000000..632ae06c --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Primitives/ResourceUnavailableError.cs @@ -0,0 +1,28 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Enums.Primitives; +#endregion + +namespace Lumina.Presentation.Web.Common.Primitives; + +/// +/// Error representing that the required resource is currently unavailable. +/// +/// The error code that uniquely identifies this error type. +/// The human-readable description of the error. +public record ResourceUnavailableError(string Code, string Description) : Error +{ + /// + /// Gets the type of this error. + /// + public override ErrorType Type => ErrorType.Unexpected; + + /// + /// Gets the error code that uniquely identifies this error type. + /// + public override string Code { get; } = Code; + + /// + /// Gets the human-readable description of the error. + /// + public override string Description { get; } = Description; +} diff --git a/src/Lumina.Presentation.Web/Common/Primitives/Result.Markers.cs b/src/Lumina.Presentation.Web/Common/Primitives/Result.Markers.cs new file mode 100644 index 00000000..108f8704 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Primitives/Result.Markers.cs @@ -0,0 +1,38 @@ +namespace Lumina.Presentation.Web.Common.Primitives; + +/// +/// Provides predefined success results for operations that don't return meaningful data, and factory methods for results. +/// +public static class Result +{ + /// + /// Represents a successful operation. + /// + public static Success Success { get; } = new(); + + /// + /// Represents a successful creation operation. + /// + public static Created Created { get; } = new(); + + /// + /// Represents a successful update operation. + /// + public static Updated Updated { get; } = new(); + + /// + /// Represents a successful deletion operation. + /// + public static Deleted Deleted { get; } = new(); + + /// + /// Creates a successful result wrapping the provided value. + /// + /// The type of the value to wrap. + /// The value to wrap in a successful result. + /// A successful result containing the provided value. + public static Result From(TValue value) + { + return Result.Success(value); + } +} diff --git a/src/Lumina.Presentation.Web/Common/Primitives/Result.cs b/src/Lumina.Presentation.Web/Common/Primitives/Result.cs new file mode 100644 index 00000000..1b509d93 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Primitives/Result.cs @@ -0,0 +1,243 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Collections.Generic; +using System.Linq; +#endregion + +namespace Lumina.Presentation.Web.Common.Primitives; + +/// +/// Primitive struct for explicitly handling success and failure cases in a functional manner. +/// +/// The type of the success value. +public readonly struct Result : IEquatable> +{ + private readonly TValue? _value; + private readonly List? _errors; + + /// + /// Gets a value indicating whether this result represents a success. + /// + public bool IsSuccess { get; } + + /// + /// Gets a value indicating whether this result represents a failure. + /// + public bool IsFailure => !IsSuccess; + + /// + /// Gets the success value. Only valid when IsSuccess is true. + /// + public TValue Value => IsSuccess ? _value! : throw new InvalidOperationException("Cannot access Value of a failed result."); + + /// + /// Gets the list of errors. Only valid when IsFailure is true. + /// + public List Errors => IsFailure + ? _errors ?? [] + : throw new InvalidOperationException("Cannot access Errors of a successful result."); + + /// + /// Returns the first error, if present. + /// + public Error FirstError => Errors[0]; + + /// + /// Initializes a new instance of the structure. + /// + /// The success value. + /// The list of errors. + /// Whether this represents a success or failure. + private Result(TValue? value, List? errors, bool isSuccess) + { + _value = value; + _errors = errors; + IsSuccess = isSuccess; + } + + /// + /// Creates a successful result with the specified value. + /// + /// The success value. + /// A successful result containing the specified value. + public static Result Success(TValue value) + { + return new Result(value, default, true); + } + + /// + /// Creates a failed result with the specified errors. + /// + /// The errors value. + /// A failed result containing the specified error. + public static Result Failure(List errors) + { + return new Result(default, errors, false); + } + + /// + /// Creates a failed result with the specified errors. + /// + /// The errors value. + /// A failed result containing the specified error. + public static Result Failure(params Error[] errors) + { + return new(default, [.. errors], false); + } + + /// + /// Custom implementation operator for converting to a . + /// + /// The value to be converted. + public static implicit operator Result(TValue value) + { + return Success(value); + } + + /// + /// Custom implementation operator for converting to a failed . + /// + /// The error to be converted. + public static implicit operator Result(Error error) + { + return Failure(error); + } + + /// + /// Custom implementation operator for converting to a failed . + /// + /// The errors to be converted. + public static implicit operator Result(List errors) + { + return Failure(errors); + } + + /// + /// Maps the success value to a new type using the provided function. + /// + /// The type of the new success value. + /// The function to transform the success value. + /// A new result with the transformed value, or the original errors. + public Result Map(Func mapper) + { + return IsSuccess + ? Result.Success(mapper(Value)) + : Result.Failure(Errors); + } + + /// + /// Chains another operation that returns a Result, allowing for monadic composition. + /// + /// The type of the new success value. + /// The function that returns a new Results. + /// The result of the chained operation, or the original error. + public Result Bind(Func> binder) + { + return IsSuccess ? binder(Value) : Result.Failure(Errors); + } + + /// + /// Executes an action if the result is successful, otherwise does nothing. + /// + /// The action to execute on success. + /// The original result for chaining. + public Result OnSuccess(Action action) + { + if (IsSuccess) + action(Value); + return this; + } + + /// + /// Executes an action if the result is a failure, otherwise does nothing. + /// + /// The action to execute on failure. + /// The original result for chaining. + public Result OnFailure(Action> action) + { + if (IsFailure) + action(Errors); + return this; + } + + /// + /// Matches the result and executes the appropriate function. + /// + /// The type of the result. + /// Function to execute on success. + /// Function to execute on failure. + /// The result of the executed function. + public TResult Match(Func onSuccess, Func, TResult> onFailure) + { + return IsSuccess ? onSuccess(Value) : onFailure(Errors); + } + + /// + /// Determines whether the specified Result is equal to the current Results. + /// + /// The Result to compare with the current Results. + /// true if the specified Result is equal to the current Result; otherwise, false. + public bool Equals(Result other) + { + if (IsSuccess != other.IsSuccess) + return false; + + return IsSuccess + ? EqualityComparer.Default.Equals(Value, other.Value) + : Errors.SequenceEqual(other.Errors); + } + + /// + /// Determines whether the specified object is equal to the current Results. + /// + /// The object to compare with the current Results. + /// true if the specified object is equal to the current Result; otherwise, false. + public override bool Equals(object? obj) + { + return obj is Result other && Equals(other); + } + + /// + /// Determines whether two specified Result instances are equal. + /// + /// The first Result to compare. + /// The second Result to compare. + /// true if the two Result instances are equal; otherwise, false. + public static bool operator ==(Result left, Result right) + { + return left.Equals(right); + } + + /// + /// Determines whether two specified Result instances are not equal. + /// + /// The first Result to compare. + /// The second Result to compare. + /// true if the two Result instances are not equal; otherwise, false. + public static bool operator !=(Result left, Result right) + { + return !(left == right); + } + + /// + /// Returns the hash code for this Results. + /// + /// A 32-bit signed integer hash code. + public override int GetHashCode() + { + return IsSuccess + ? HashCode.Combine(IsSuccess, Value) + : HashCode.Combine(IsSuccess, Errors); + } + + /// + /// Customized ToString() method. + /// + /// Custom string value showing relevant data for current result. + public override string ToString() + { + return IsSuccess + ? $"Success: {Value?.ToString()}" + : $"Failure: [{string.Join(", ", Errors.Select(error => error.ToString()))}]"; + } +} diff --git a/src/Lumina.Presentation.Web/Common/Primitives/Success.cs b/src/Lumina.Presentation.Web/Common/Primitives/Success.cs new file mode 100644 index 00000000..9b98eba1 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Primitives/Success.cs @@ -0,0 +1,6 @@ +namespace Lumina.Presentation.Web.Common.Primitives; + +/// +/// Represents a successful operation result. +/// +public readonly record struct Success; diff --git a/src/Lumina.Presentation.Web/Common/Primitives/TimeoutError.cs b/src/Lumina.Presentation.Web/Common/Primitives/TimeoutError.cs new file mode 100644 index 00000000..181f2614 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Primitives/TimeoutError.cs @@ -0,0 +1,28 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Enums.Primitives; +#endregion + +namespace Lumina.Presentation.Web.Common.Primitives; + +/// +/// Error representing that the operation timed out before completion. +/// +/// The error code that uniquely identifies this error type. +/// The human-readable description of the error. +public record TimeoutError(string Code, string Description) : Error +{ + /// + /// Gets the type of this error. + /// + public override ErrorType Type => ErrorType.Unexpected; + + /// + /// Gets the error code that uniquely identifies this error type. + /// + public override string Code { get; } = Code; + + /// + /// Gets the human-readable description of the error. + /// + public override string Description { get; } = Description; +} diff --git a/src/Lumina.Presentation.Web/Common/Primitives/UnauthorizedError.cs b/src/Lumina.Presentation.Web/Common/Primitives/UnauthorizedError.cs new file mode 100644 index 00000000..8d4ba4a8 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Primitives/UnauthorizedError.cs @@ -0,0 +1,28 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Enums.Primitives; +#endregion + +namespace Lumina.Presentation.Web.Common.Primitives; + +/// +/// Error representing that authentication is required or has failed. +/// +/// The error code that uniquely identifies this error type. +/// The human-readable description of the error. +public record UnauthorizedError(string Code, string Description) : Error +{ + /// + /// Gets the type of this error. + /// + public override ErrorType Type => ErrorType.Unauthorized; + + /// + /// Gets the error code that uniquely identifies this error type. + /// + public override string Code { get; } = Code; + + /// + /// Gets the human-readable description of the error. + /// + public override string Description { get; } = Description; +} diff --git a/src/Lumina.Presentation.Web/Common/Primitives/UnexpectedError.cs b/src/Lumina.Presentation.Web/Common/Primitives/UnexpectedError.cs new file mode 100644 index 00000000..65bfe0c0 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Primitives/UnexpectedError.cs @@ -0,0 +1,28 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Enums.Primitives; +#endregion + +namespace Lumina.Presentation.Web.Common.Primitives; + +/// +/// Error representing that an unexpected error occurred. +/// +/// The error code that uniquely identifies this error type. +/// The human-readable description of the error. +public record UnexpectedError(string Code, string Description) : Error +{ + /// + /// Gets the type of this error. + /// + public override ErrorType Type => ErrorType.Unexpected; + + /// + /// Gets the error code that uniquely identifies this error type. + /// + public override string Code { get; } = Code; + + /// + /// Gets the human-readable description of the error. + /// + public override string Description { get; } = Description; +} diff --git a/src/Lumina.Presentation.Web/Common/Primitives/Updated.cs b/src/Lumina.Presentation.Web/Common/Primitives/Updated.cs new file mode 100644 index 00000000..3285d2c0 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Primitives/Updated.cs @@ -0,0 +1,6 @@ +namespace Lumina.Presentation.Web.Common.Primitives; + +/// +/// Represents a successful update operation result. +/// +public readonly record struct Updated; diff --git a/src/Lumina.Presentation.Web/Common/Primitives/ValidationError.cs b/src/Lumina.Presentation.Web/Common/Primitives/ValidationError.cs new file mode 100644 index 00000000..e49c98be --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Primitives/ValidationError.cs @@ -0,0 +1,28 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Enums.Primitives; +#endregion + +namespace Lumina.Presentation.Web.Common.Primitives; + +/// +/// Error representing that the input or data failed validation rules. +/// +/// The error code that uniquely identifies this error type. +/// The human-readable description of the error. +public record ValidationError(string Code, string Description) : Error +{ + /// + /// Gets the type of this error. + /// + public override ErrorType Type => ErrorType.Validation; + + /// + /// Gets the error code that uniquely identifies this error type. + /// + public override string Code { get; } = Code; + + /// + /// Gets the human-readable description of the error. + /// + public override string Description { get; } = Description; +}