Class Error
- Namespace
- Trellis
- Assembly
- Trellis.Results.dll
Base class for all error types in the functional DDD library. Errors represent failure states and contain structured information about what went wrong.
public class Error : IEquatable<Error>
- Inheritance
-
Error
- Implements
- Derived
- Inherited Members
- Extension Methods
Remarks
Use the static factory methods (Validation, NotFound, etc.) to create specific error types. All errors have a Code for programmatic handling and a Detail for human-readable messages.
Constructors
Error(string, string)
Initializes a new instance of the Error class with the specified detail and code.
public Error(string detail, string code)
Parameters
Error(string, string, string?)
Initializes a new instance of the Error class with the specified detail, code, and instance identifier.
public Error(string detail, string code, string? instance)
Parameters
detailstringThe human-readable error description.
codestringThe machine-readable error code.
instancestringAn optional identifier for the specific instance that caused the error.
Properties
Code
Gets the machine-readable error code. Use this for programmatic error handling.
public string Code { get; }
Property Value
- string
A string code like "validation.error" or "not.found.error".
Detail
Gets the human-readable error description. Use this for displaying error messages to users or in logs.
public string Detail { get; }
Property Value
- string
A descriptive message explaining what went wrong.
Instance
Gets an optional identifier for the specific instance that caused the error (e.g., a resource ID).
public string? Instance { get; }
Property Value
- string
An instance identifier, or null if not applicable.
Methods
BadRequest(string, string?)
Creates a BadRequestError indicating the request was malformed or invalid.
public static BadRequestError BadRequest(string detail, string? instance = null)
Parameters
detailstringDescription of why the request is bad.
instancestringOptional identifier for the bad request.
Returns
Remarks
Use this for syntactic errors or malformed requests, not for business rule violations (use Validation instead).
BadRequest(string, string, string?)
Creates a BadRequestError with a custom error code.
public static BadRequestError BadRequest(string detail, string code, string? instance)
Parameters
detailstringDescription of why the request is bad.
codestringCustom error code to use instead of the default "bad.request.error".
instancestringOptional identifier for the bad request.
Returns
- BadRequestError
A BadRequestError with the specified code.
BadRequest<TInstance>(string, TInstance)
Creates a BadRequestError indicating the request was malformed or invalid.
public static BadRequestError BadRequest<TInstance>(string detail, TInstance instance) where TInstance : IFormattable
Parameters
detailstringDescription of why the request is bad.
instanceTInstanceOptional identifier for the bad request.
Returns
Type Parameters
TInstance
Remarks
Use this for syntactic errors or malformed requests, not for business rule violations (use Validation instead).
Conflict(string, string?)
Creates a ConflictError indicating a conflict with the current state.
public static ConflictError Conflict(string detail, string? instance = null)
Parameters
detailstringDescription of the conflict.
instancestringOptional identifier for the conflicting resource.
Returns
Examples
Error.Conflict("Email address already in use")
Error.Conflict("Cannot delete user with active subscriptions")
Conflict(string, string, string?)
Creates a ConflictError with a custom error code.
public static ConflictError Conflict(string detail, string code, string? instance)
Parameters
detailstringDescription of the conflict.
codestringCustom error code to use instead of the default "conflict.error".
instancestringOptional identifier for the conflicting resource.
Returns
- ConflictError
A ConflictError with the specified code.
Conflict<TInstance>(string, TInstance)
Creates a ConflictError indicating a conflict with the current state.
public static ConflictError Conflict<TInstance>(string detail, TInstance instance) where TInstance : IFormattable
Parameters
detailstringDescription of the conflict.
instanceTInstanceOptional identifier for the conflicting resource.
Returns
Type Parameters
TInstance
Examples
Error.Conflict("Email address already in use")
Error.Conflict("Cannot delete user with active subscriptions")
ContentTooLarge(string, string, RetryAfterValue?, string?)
Creates a ContentTooLargeError with a custom error code.
public static ContentTooLargeError ContentTooLarge(string detail, string code, RetryAfterValue? retryAfter = null, string? instance = null)
Parameters
detailstringDescription of why the content is too large.
codestringCustom error code to use instead of the default "content.too.large.error".
retryAfterRetryAfterValueOptional retry-after value for temporary conditions.
instancestringOptional identifier for the resource.
Returns
- ContentTooLargeError
A ContentTooLargeError with the specified code.
ContentTooLarge(string, RetryAfterValue?, string?)
Creates a ContentTooLargeError indicating the request content is too large.
public static ContentTooLargeError ContentTooLarge(string detail, RetryAfterValue? retryAfter = null, string? instance = null)
Parameters
detailstringDescription of why the content is too large.
retryAfterRetryAfterValueOptional retry-after value for temporary conditions.
instancestringOptional identifier for the resource.
Returns
Remarks
Maps to HTTP 413 Content Too Large.
Domain(string, string?)
Creates a DomainError indicating a business rule violation.
public static DomainError Domain(string detail, string? instance = null)
Parameters
detailstringDescription of the business rule that was violated.
instancestringOptional identifier for the entity or operation.
Returns
Examples
Error.Domain("Cannot withdraw more than account balance")
Error.Domain("Minimum order quantity is 10 units")
Error.Domain("Cannot cancel order after shipment")
Remarks
Use this for domain logic violations that prevent the operation from completing. This is distinct from validation errors (field-level) and conflicts (state-based). Maps to HTTP 422 Unprocessable Entity.
Domain(string, string, string?)
Creates a DomainError with a custom error code.
public static DomainError Domain(string detail, string code, string? instance)
Parameters
detailstringDescription of the business rule that was violated.
codestringCustom error code to use instead of the default "domain.error".
instancestringOptional identifier for the entity or operation.
Returns
- DomainError
A DomainError with the specified code.
Domain<TInstance>(string, TInstance)
Creates a DomainError indicating a business rule violation.
public static DomainError Domain<TInstance>(string detail, TInstance instance) where TInstance : IFormattable
Parameters
detailstringDescription of the business rule that was violated.
instanceTInstanceOptional identifier for the entity or operation.
Returns
Type Parameters
TInstance
Examples
Error.Domain("Cannot withdraw more than account balance")
Error.Domain("Minimum order quantity is 10 units")
Error.Domain("Cannot cancel order after shipment")
Remarks
Use this for domain logic violations that prevent the operation from completing. This is distinct from validation errors (field-level) and conflicts (state-based). Maps to HTTP 422 Unprocessable Entity.
Equals(object?)
Determines whether the specified object is equal to the current Error instance.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current Error instance.
Returns
- bool
true if the specified object is an Error and is equal to the current instance; otherwise, false.
Remarks
This method supports object-based equality comparison. Use this method when the type of the object to compare is not known at compile time.
Equals(Error?)
Determines equality based solely on the error Code.
public bool Equals(Error? other)
Parameters
otherErrorThe error to compare with.
Returns
- bool
True if the error codes match; false otherwise.
Remarks
IMPORTANT: Two errors are considered equal if they have the same Code, regardless of their Detail, Instance, or concrete type. This design allows treating errors with the same code as equivalent for programmatic handling. Example: Error.NotFound("User not found", "user-1") == Error.NotFound("Product not found", "user-1") returns true because both have the code "not.found.error".
Forbidden(string, string?)
Creates a ForbiddenError indicating the user lacks permission.
public static ForbiddenError Forbidden(string detail, string? instance = null)
Parameters
detailstringDescription of why access is forbidden.
instancestringOptional identifier for the forbidden resource.
Returns
Remarks
Use this when the user is authenticated but doesn't have permission to access the resource.
Forbidden(string, string, string?)
Creates a ForbiddenError with a custom error code.
public static ForbiddenError Forbidden(string detail, string code, string? instance)
Parameters
detailstringDescription of why access is forbidden.
codestringCustom error code to use instead of the default "forbidden.error".
instancestringOptional identifier for the forbidden resource.
Returns
- ForbiddenError
A ForbiddenError with the specified code.
Forbidden<TInstance>(string, TInstance)
Creates a ForbiddenError indicating the user lacks permission.
public static ForbiddenError Forbidden<TInstance>(string detail, TInstance instance) where TInstance : IFormattable
Parameters
detailstringDescription of why access is forbidden.
instanceTInstanceOptional identifier for the forbidden resource.
Returns
Type Parameters
TInstance
Remarks
Use this when the user is authenticated but doesn't have permission to access the resource.
GetHashCode()
Serves as the default hash function.
public override int GetHashCode()
Returns
- int
A hash code for the current object.
Gone(string, string?)
Creates a GoneError indicating a resource has been permanently removed.
public static GoneError Gone(string detail, string? instance = null)
Parameters
detailstringDescription of why the resource is gone.
instancestringOptional identifier for the removed resource.
Returns
Remarks
Use this instead of NotFound(string, string?) when the server knows the resource previously existed and has been intentionally removed. Maps to HTTP 410 Gone.
Gone(string, string, string?)
Creates a GoneError with a custom error code.
public static GoneError Gone(string detail, string code, string? instance)
Parameters
detailstringDescription of why the resource is gone.
codestringCustom error code to use instead of the default "gone.error".
instancestringOptional identifier for the removed resource.
Returns
Gone<TInstance>(string, TInstance)
Creates a GoneError indicating a resource has been permanently removed.
public static GoneError Gone<TInstance>(string detail, TInstance instance) where TInstance : IFormattable
Parameters
detailstringDescription of why the resource is gone.
instanceTInstanceOptional identifier for the removed resource.
Returns
Type Parameters
TInstance
Remarks
Use this instead of NotFound(string, string?) when the server knows the resource previously existed and has been intentionally removed. Maps to HTTP 410 Gone.
MethodNotAllowed(string, IReadOnlyList<string>, string?)
Creates a MethodNotAllowedError indicating the HTTP method is not supported.
public static MethodNotAllowedError MethodNotAllowed(string detail, IReadOnlyList<string> allowedMethods, string? instance = null)
Parameters
detailstringDescription of why the method is not allowed.
allowedMethodsIReadOnlyList<string>The HTTP methods the target resource supports. Emitted as the
Allowheader.instancestringOptional identifier for the resource.
Returns
Remarks
Per RFC 9110 §15.5.6, a 405 response MUST include an Allow header.
Maps to HTTP 405 Method Not Allowed.
MethodNotAllowed(string, IReadOnlyList<string>, string, string?)
Creates a MethodNotAllowedError with a custom error code.
public static MethodNotAllowedError MethodNotAllowed(string detail, IReadOnlyList<string> allowedMethods, string code, string? instance)
Parameters
detailstringDescription of why the method is not allowed.
allowedMethodsIReadOnlyList<string>The HTTP methods the target resource supports.
codestringCustom error code to use instead of the default "method.not.allowed.error".
instancestringOptional identifier for the resource.
Returns
- MethodNotAllowedError
A MethodNotAllowedError with the specified code.
NotAcceptable(string, string?)
Creates a NotAcceptableError indicating no acceptable representation is available.
public static NotAcceptableError NotAcceptable(string detail, string? instance = null)
Parameters
detailstringDescription of why no acceptable representation is available.
instancestringOptional identifier for the resource.
Returns
Remarks
Maps to HTTP 406 Not Acceptable.
NotAcceptable(string, string, string?)
Creates a NotAcceptableError with a custom error code.
public static NotAcceptableError NotAcceptable(string detail, string code, string? instance)
Parameters
detailstringDescription of why no acceptable representation is available.
codestringCustom error code to use instead of the default "not.acceptable.error".
instancestringOptional identifier for the resource.
Returns
- NotAcceptableError
A NotAcceptableError with the specified code.
NotAcceptable<TInstance>(string, TInstance)
Creates a NotAcceptableError indicating no acceptable representation is available.
public static NotAcceptableError NotAcceptable<TInstance>(string detail, TInstance instance) where TInstance : IFormattable
Parameters
detailstringDescription of why no acceptable representation is available.
instanceTInstanceOptional identifier for the resource.
Returns
Type Parameters
TInstance
Remarks
Maps to HTTP 406 Not Acceptable.
NotFound(string, string?)
Creates a NotFoundError indicating a requested resource was not found.
public static NotFoundError NotFound(string detail, string? instance = null)
Parameters
detailstringDescription of what was not found.
instancestringOptional identifier for the missing resource.
Returns
Examples
Error.NotFound($"User with ID {userId} not found", userId)
Error.NotFound("Product not found in catalog")
NotFound(string, string, string?)
Creates a NotFoundError with a custom error code.
public static NotFoundError NotFound(string detail, string code, string? instance)
Parameters
detailstringDescription of what was not found.
codestringCustom error code to use instead of the default "not.found.error".
instancestringOptional identifier for the missing resource.
Returns
- NotFoundError
A NotFoundError with the specified code.
NotFound<TInstance>(string, TInstance)
Creates a NotFoundError indicating a requested resource was not found.
public static NotFoundError NotFound<TInstance>(string detail, TInstance instance) where TInstance : IFormattable
Parameters
detailstringDescription of what was not found.
instanceTInstanceOptional identifier for the missing resource.
Returns
Type Parameters
TInstance
Examples
Error.NotFound($"User with ID {userId} not found", userId)
Error.NotFound("Product not found in catalog")
PreconditionFailed(string, string?)
Creates a PreconditionFailedError indicating a conditional request header
(e.g., If-Match) evaluated to false per RFC 9110 §13.1.1.
public static PreconditionFailedError PreconditionFailed(string detail, string? instance = null)
Parameters
detailstringDescription of the precondition failure.
instancestringOptional identifier for the affected resource.
Returns
Examples
Error.PreconditionFailed("Resource has been modified. Please reload and retry.")
PreconditionFailed(string, string, string?)
Creates a PreconditionFailedError with a custom error code.
public static PreconditionFailedError PreconditionFailed(string detail, string code, string? instance)
Parameters
detailstringDescription of the precondition failure.
codestringCustom error code to use instead of the default "precondition.failed.error".
instancestringOptional identifier for the affected resource.
Returns
- PreconditionFailedError
A PreconditionFailedError with the specified code.
PreconditionFailed<TInstance>(string, TInstance)
Creates a PreconditionFailedError indicating a conditional request header
(e.g., If-Match) evaluated to false per RFC 9110 §13.1.1.
public static PreconditionFailedError PreconditionFailed<TInstance>(string detail, TInstance instance) where TInstance : IFormattable
Parameters
detailstringDescription of the precondition failure.
instanceTInstanceOptional identifier for the affected resource.
Returns
Type Parameters
TInstance
Examples
Error.PreconditionFailed("Resource has been modified. Please reload and retry.")
PreconditionRequired(string, string?)
Creates a PreconditionRequiredError indicating the server requires
a conditional request header (e.g., If-Match) per RFC 6585 §3.
public static PreconditionRequiredError PreconditionRequired(string detail, string? instance = null)
Parameters
detailstringDescription of the required precondition.
instancestringOptional identifier for the affected resource.
Returns
PreconditionRequired(string, string, string?)
Creates a PreconditionRequiredError with a custom error code.
public static PreconditionRequiredError PreconditionRequired(string detail, string code, string? instance)
Parameters
detailstringDescription of the required precondition.
codestringCustom error code to use instead of the default "precondition.required.error".
instancestringOptional identifier for the affected resource.
Returns
- PreconditionRequiredError
A PreconditionRequiredError with the specified code.
PreconditionRequired<TInstance>(string, TInstance)
Creates a PreconditionRequiredError indicating the server requires
a conditional request header (e.g., If-Match) per RFC 6585 §3.
public static PreconditionRequiredError PreconditionRequired<TInstance>(string detail, TInstance instance) where TInstance : IFormattable
Parameters
detailstringDescription of the required precondition.
instanceTInstanceOptional identifier for the affected resource.
Returns
Type Parameters
TInstance
RangeNotSatisfiable(string, long, string?)
Creates a RangeNotSatisfiableError indicating the requested range cannot be served.
public static RangeNotSatisfiableError RangeNotSatisfiable(string detail, long completeLength, string? instance = null)
Parameters
detailstringDescription of why the range is not satisfiable.
completeLengthlongThe complete length of the representation for the
Content-Rangeheader.instancestringOptional identifier for the resource.
Returns
Remarks
Maps to HTTP 416 Range Not Satisfiable.
RangeNotSatisfiable(string, long, string, string, string?)
Creates a RangeNotSatisfiableError with a custom error code.
public static RangeNotSatisfiableError RangeNotSatisfiable(string detail, long completeLength, string code, string unit = "bytes", string? instance = null)
Parameters
detailstringDescription of why the range is not satisfiable.
completeLengthlongThe complete length of the representation.
codestringCustom error code to use instead of the default "range.not.satisfiable.error".
unitstringThe range unit (defaults to "bytes").
instancestringOptional identifier for the resource.
Returns
- RangeNotSatisfiableError
A RangeNotSatisfiableError with the specified code.
RateLimit(string, string?)
Creates a RateLimitError indicating too many requests have been made.
public static RateLimitError RateLimit(string detail, string? instance = null)
Parameters
detailstringDescription of the rate limit violation.
instancestringOptional identifier for the client or resource being rate limited.
Returns
Examples
Error.RateLimit("API rate limit exceeded. Please try again in 60 seconds")
Error.RateLimit("Too many login attempts. Account temporarily locked")
Remarks
Use this when a client has exceeded their request quota or rate limit. Maps to HTTP 429 Too Many Requests.
RateLimit(string, string, string?)
Creates a RateLimitError with a custom error code.
public static RateLimitError RateLimit(string detail, string code, string? instance)
Parameters
detailstringDescription of the rate limit violation.
codestringCustom error code to use instead of the default "rate.limit.error".
instancestringOptional identifier for the client or resource being rate limited.
Returns
- RateLimitError
A RateLimitError with the specified code.
RateLimit(string, RetryAfterValue, string?)
Creates a RateLimitError with retry-after metadata.
public static RateLimitError RateLimit(string detail, RetryAfterValue retryAfter, string? instance = null)
Parameters
detailstringDescription of the rate limit violation.
retryAfterRetryAfterValueThe retry-after value indicating when the client may retry.
instancestringOptional identifier for the client or resource being rate limited.
Returns
- RateLimitError
A RateLimitError with retry-after metadata.
RateLimit<TInstance>(string, TInstance)
Creates a RateLimitError indicating too many requests have been made.
public static RateLimitError RateLimit<TInstance>(string detail, TInstance instance) where TInstance : IFormattable
Parameters
detailstringDescription of the rate limit violation.
instanceTInstanceOptional identifier for the client or resource being rate limited.
Returns
Type Parameters
TInstance
Examples
Error.RateLimit("API rate limit exceeded. Please try again in 60 seconds")
Error.RateLimit("Too many login attempts. Account temporarily locked")
Remarks
Use this when a client has exceeded their request quota or rate limit. Maps to HTTP 429 Too Many Requests.
ServiceUnavailable(string, string?)
Creates a ServiceUnavailableError indicating temporary service unavailability.
public static ServiceUnavailableError ServiceUnavailable(string detail, string? instance = null)
Parameters
detailstringDescription of why the service is unavailable.
instancestringOptional identifier for the unavailable service or resource.
Returns
Examples
Error.ServiceUnavailable("Service is under maintenance. Please try again later")
Error.ServiceUnavailable("External payment gateway is temporarily unavailable")
Remarks
Use this when the service is temporarily unable to handle the request. This indicates a temporary condition - the service is expected to be available again. Maps to HTTP 503 Service Unavailable.
ServiceUnavailable(string, string, string?)
Creates a ServiceUnavailableError with a custom error code.
public static ServiceUnavailableError ServiceUnavailable(string detail, string code, string? instance)
Parameters
detailstringDescription of why the service is unavailable.
codestringCustom error code to use instead of the default "service.unavailable.error".
instancestringOptional identifier for the unavailable service or resource.
Returns
- ServiceUnavailableError
A ServiceUnavailableError with the specified code.
ServiceUnavailable(string, RetryAfterValue, string?)
Creates a ServiceUnavailableError with retry-after metadata.
public static ServiceUnavailableError ServiceUnavailable(string detail, RetryAfterValue retryAfter, string? instance = null)
Parameters
detailstringDescription of why the service is unavailable.
retryAfterRetryAfterValueThe retry-after value indicating when the service may resume.
instancestringOptional identifier for the unavailable service or resource.
Returns
- ServiceUnavailableError
A ServiceUnavailableError with retry-after metadata.
ServiceUnavailable<TInstance>(string, TInstance)
Creates a ServiceUnavailableError indicating temporary service unavailability.
public static ServiceUnavailableError ServiceUnavailable<TInstance>(string detail, TInstance instance) where TInstance : IFormattable
Parameters
detailstringDescription of why the service is unavailable.
instanceTInstanceOptional identifier for the unavailable service or resource.
Returns
Type Parameters
TInstance
Examples
Error.ServiceUnavailable("Service is under maintenance. Please try again later")
Error.ServiceUnavailable("External payment gateway is temporarily unavailable")
Remarks
Use this when the service is temporarily unable to handle the request. This indicates a temporary condition - the service is expected to be available again. Maps to HTTP 503 Service Unavailable.
ToString()
Returns a string that represents the current object, including its type, code, detail, and instance information.
public override string ToString()
Returns
- string
A string containing the type name, code, detail, and instance values of the object. If the instance is null, "N/A" is used.
Unauthorized(string, string?)
Creates an UnauthorizedError indicating authentication is required.
public static UnauthorizedError Unauthorized(string detail, string? instance = null)
Parameters
detailstringDescription of why authorization failed.
instancestringOptional identifier for the unauthorized request.
Returns
Remarks
Use this when the user is not authenticated (not logged in).
Unauthorized(string, string, string?)
Creates an UnauthorizedError with a custom error code.
public static UnauthorizedError Unauthorized(string detail, string code, string? instance)
Parameters
detailstringDescription of why authorization failed.
codestringCustom error code to use instead of the default "unauthorized.error".
instancestringOptional identifier for the unauthorized request.
Returns
- UnauthorizedError
An UnauthorizedError with the specified code.
Unauthorized<TInstance>(string, TInstance)
Creates an UnauthorizedError indicating authentication is required.
public static UnauthorizedError Unauthorized<TInstance>(string detail, TInstance instance) where TInstance : IFormattable
Parameters
detailstringDescription of why authorization failed.
instanceTInstanceOptional identifier for the unauthorized request.
Returns
Type Parameters
TInstance
Remarks
Use this when the user is not authenticated (not logged in).
Unexpected(string, string?)
Creates an UnexpectedError indicating an unexpected system error occurred.
public static UnexpectedError Unexpected(string detail, string? instance = null)
Parameters
detailstringDescription of what went wrong.
instancestringOptional identifier for the operation that failed.
Returns
Remarks
Use this for system errors, infrastructure failures, or exceptions. This typically maps to HTTP 500 Internal Server Error.
Unexpected(string, string, string?)
Creates an UnexpectedError with a custom error code.
public static UnexpectedError Unexpected(string detail, string code, string? instance)
Parameters
detailstringDescription of what went wrong.
codestringCustom error code to use instead of the default "unexpected.error".
instancestringOptional identifier for the operation that failed.
Returns
- UnexpectedError
An UnexpectedError with the specified code.
Unexpected<TInstance>(string, TInstance)
Creates an UnexpectedError indicating an unexpected system error occurred.
public static UnexpectedError Unexpected<TInstance>(string detail, TInstance instance) where TInstance : IFormattable
Parameters
detailstringDescription of what went wrong.
instanceTInstanceOptional identifier for the operation that failed.
Returns
Type Parameters
TInstance
Remarks
Use this for system errors, infrastructure failures, or exceptions. This typically maps to HTTP 500 Internal Server Error.
UnsupportedMediaType(string, string?)
Creates an UnsupportedMediaTypeError indicating the content type is not supported.
public static UnsupportedMediaTypeError UnsupportedMediaType(string detail, string? instance = null)
Parameters
detailstringDescription of why the media type is not supported.
instancestringOptional identifier for the resource.
Returns
Remarks
Maps to HTTP 415 Unsupported Media Type.
UnsupportedMediaType(string, string, string?)
Creates an UnsupportedMediaTypeError with a custom error code.
public static UnsupportedMediaTypeError UnsupportedMediaType(string detail, string code, string? instance)
Parameters
detailstringDescription of why the media type is not supported.
codestringCustom error code to use instead of the default "unsupported.media.type.error".
instancestringOptional identifier for the resource.
Returns
- UnsupportedMediaTypeError
An UnsupportedMediaTypeError with the specified code.
UnsupportedMediaType<TInstance>(string, TInstance)
Creates an UnsupportedMediaTypeError indicating the content type is not supported.
public static UnsupportedMediaTypeError UnsupportedMediaType<TInstance>(string detail, TInstance instance) where TInstance : IFormattable
Parameters
detailstringDescription of why the media type is not supported.
instanceTInstanceOptional identifier for the resource.
Returns
Type Parameters
TInstance
Remarks
Maps to HTTP 415 Unsupported Media Type.
Validation(ImmutableArray<FieldError>, string, string?)
Creates a ValidationError for multiple field validation failures.
public static ValidationError Validation(ImmutableArray<ValidationError.FieldError> fieldDetails, string detail = "", string? instance = null)
Parameters
fieldDetailsImmutableArray<ValidationError.FieldError>Collection of field-specific validation errors.
detailstringOverall error description.
instancestringOptional identifier for the instance being validated.
Returns
- ValidationError
A ValidationError containing all field errors.
Examples
var errors = ImmutableArray.Create(
new FieldError("email", "Invalid format"),
new FieldError("age", "Must be 18 or older")
);
Error.Validation(errors, "User validation failed")
Validation(ImmutableArray<FieldError>, string, string?, string)
Creates a ValidationError for multiple field validation failures with a custom error code.
public static ValidationError Validation(ImmutableArray<ValidationError.FieldError> fieldDetails, string detail, string? instance, string code)
Parameters
fieldDetailsImmutableArray<ValidationError.FieldError>Collection of field-specific validation errors.
detailstringOverall error description.
instancestringOptional identifier for the instance being validated.
codestringCustom error code to use instead of the default "validation.error".
Returns
- ValidationError
A ValidationError containing all field errors with the specified code.
Validation(string, string, string?, string?)
Creates a ValidationError for a single field validation failure.
public static ValidationError Validation(string fieldDetail, string fieldName = "", string? detail = null, string? instance = null)
Parameters
fieldDetailstringDescription of what's wrong with the field value.
fieldNamestringName of the field that failed validation. Empty string if not field-specific.
detailstringOptional overall error detail. If null, uses fieldDetail.
instancestringOptional identifier for the instance being validated.
Returns
- ValidationError
A ValidationError representing the validation failure.
Examples
Error.Validation("Email address is not valid", "email")
Error.Validation("Age must be 18 or older", "age")