Table of Contents

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

detail string

The human-readable error description.

code string

The machine-readable error code.

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

detail string

The human-readable error description.

code string

The machine-readable error code.

instance string

An 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

detail string

Description of why the request is bad.

instance string

Optional identifier for the bad request.

Returns

BadRequestError

A BadRequestError.

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

detail string

Description of why the request is bad.

code string

Custom error code to use instead of the default "bad.request.error".

instance string

Optional 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

detail string

Description of why the request is bad.

instance TInstance

Optional identifier for the bad request.

Returns

BadRequestError

A BadRequestError.

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

detail string

Description of the conflict.

instance string

Optional identifier for the conflicting resource.

Returns

ConflictError

A ConflictError.

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

detail string

Description of the conflict.

code string

Custom error code to use instead of the default "conflict.error".

instance string

Optional 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

detail string

Description of the conflict.

instance TInstance

Optional identifier for the conflicting resource.

Returns

ConflictError

A ConflictError.

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

detail string

Description of why the content is too large.

code string

Custom error code to use instead of the default "content.too.large.error".

retryAfter RetryAfterValue

Optional retry-after value for temporary conditions.

instance string

Optional 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

detail string

Description of why the content is too large.

retryAfter RetryAfterValue

Optional retry-after value for temporary conditions.

instance string

Optional identifier for the resource.

Returns

ContentTooLargeError

A ContentTooLargeError.

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

detail string

Description of the business rule that was violated.

instance string

Optional identifier for the entity or operation.

Returns

DomainError

A DomainError.

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

detail string

Description of the business rule that was violated.

code string

Custom error code to use instead of the default "domain.error".

instance string

Optional 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

detail string

Description of the business rule that was violated.

instance TInstance

Optional identifier for the entity or operation.

Returns

DomainError

A DomainError.

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

obj object

The 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

other Error

The 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

detail string

Description of why access is forbidden.

instance string

Optional identifier for the forbidden resource.

Returns

ForbiddenError

A ForbiddenError.

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

detail string

Description of why access is forbidden.

code string

Custom error code to use instead of the default "forbidden.error".

instance string

Optional 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

detail string

Description of why access is forbidden.

instance TInstance

Optional identifier for the forbidden resource.

Returns

ForbiddenError

A ForbiddenError.

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

detail string

Description of why the resource is gone.

instance string

Optional identifier for the removed resource.

Returns

GoneError

A GoneError.

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

detail string

Description of why the resource is gone.

code string

Custom error code to use instead of the default "gone.error".

instance string

Optional identifier for the removed resource.

Returns

GoneError

A GoneError with the specified code.

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

detail string

Description of why the resource is gone.

instance TInstance

Optional identifier for the removed resource.

Returns

GoneError

A GoneError.

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

detail string

Description of why the method is not allowed.

allowedMethods IReadOnlyList<string>

The HTTP methods the target resource supports. Emitted as the Allow header.

instance string

Optional identifier for the resource.

Returns

MethodNotAllowedError

A MethodNotAllowedError.

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

detail string

Description of why the method is not allowed.

allowedMethods IReadOnlyList<string>

The HTTP methods the target resource supports.

code string

Custom error code to use instead of the default "method.not.allowed.error".

instance string

Optional 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

detail string

Description of why no acceptable representation is available.

instance string

Optional identifier for the resource.

Returns

NotAcceptableError

A NotAcceptableError.

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

detail string

Description of why no acceptable representation is available.

code string

Custom error code to use instead of the default "not.acceptable.error".

instance string

Optional 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

detail string

Description of why no acceptable representation is available.

instance TInstance

Optional identifier for the resource.

Returns

NotAcceptableError

A NotAcceptableError.

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

detail string

Description of what was not found.

instance string

Optional identifier for the missing resource.

Returns

NotFoundError

A NotFoundError.

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

detail string

Description of what was not found.

code string

Custom error code to use instead of the default "not.found.error".

instance string

Optional 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

detail string

Description of what was not found.

instance TInstance

Optional identifier for the missing resource.

Returns

NotFoundError

A NotFoundError.

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

detail string

Description of the precondition failure.

instance string

Optional identifier for the affected resource.

Returns

PreconditionFailedError

A PreconditionFailedError.

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

detail string

Description of the precondition failure.

code string

Custom error code to use instead of the default "precondition.failed.error".

instance string

Optional 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

detail string

Description of the precondition failure.

instance TInstance

Optional identifier for the affected resource.

Returns

PreconditionFailedError

A PreconditionFailedError.

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

detail string

Description of the required precondition.

instance string

Optional identifier for the affected resource.

Returns

PreconditionRequiredError

A PreconditionRequiredError.

PreconditionRequired(string, string, string?)

Creates a PreconditionRequiredError with a custom error code.

public static PreconditionRequiredError PreconditionRequired(string detail, string code, string? instance)

Parameters

detail string

Description of the required precondition.

code string

Custom error code to use instead of the default "precondition.required.error".

instance string

Optional 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

detail string

Description of the required precondition.

instance TInstance

Optional identifier for the affected resource.

Returns

PreconditionRequiredError

A PreconditionRequiredError.

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

detail string

Description of why the range is not satisfiable.

completeLength long

The complete length of the representation for the Content-Range header.

instance string

Optional identifier for the resource.

Returns

RangeNotSatisfiableError

A RangeNotSatisfiableError.

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

detail string

Description of why the range is not satisfiable.

completeLength long

The complete length of the representation.

code string

Custom error code to use instead of the default "range.not.satisfiable.error".

unit string

The range unit (defaults to "bytes").

instance string

Optional 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

detail string

Description of the rate limit violation.

instance string

Optional identifier for the client or resource being rate limited.

Returns

RateLimitError

A RateLimitError.

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

detail string

Description of the rate limit violation.

code string

Custom error code to use instead of the default "rate.limit.error".

instance string

Optional 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

detail string

Description of the rate limit violation.

retryAfter RetryAfterValue

The retry-after value indicating when the client may retry.

instance string

Optional 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

detail string

Description of the rate limit violation.

instance TInstance

Optional identifier for the client or resource being rate limited.

Returns

RateLimitError

A RateLimitError.

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

detail string

Description of why the service is unavailable.

instance string

Optional identifier for the unavailable service or resource.

Returns

ServiceUnavailableError

A ServiceUnavailableError.

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

detail string

Description of why the service is unavailable.

code string

Custom error code to use instead of the default "service.unavailable.error".

instance string

Optional 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

detail string

Description of why the service is unavailable.

retryAfter RetryAfterValue

The retry-after value indicating when the service may resume.

instance string

Optional 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

detail string

Description of why the service is unavailable.

instance TInstance

Optional identifier for the unavailable service or resource.

Returns

ServiceUnavailableError

A ServiceUnavailableError.

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

detail string

Description of why authorization failed.

instance string

Optional identifier for the unauthorized request.

Returns

UnauthorizedError

An UnauthorizedError.

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

detail string

Description of why authorization failed.

code string

Custom error code to use instead of the default "unauthorized.error".

instance string

Optional 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

detail string

Description of why authorization failed.

instance TInstance

Optional identifier for the unauthorized request.

Returns

UnauthorizedError

An UnauthorizedError.

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

detail string

Description of what went wrong.

instance string

Optional identifier for the operation that failed.

Returns

UnexpectedError

An UnexpectedError.

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

detail string

Description of what went wrong.

code string

Custom error code to use instead of the default "unexpected.error".

instance string

Optional 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

detail string

Description of what went wrong.

instance TInstance

Optional identifier for the operation that failed.

Returns

UnexpectedError

An UnexpectedError.

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

detail string

Description of why the media type is not supported.

instance string

Optional identifier for the resource.

Returns

UnsupportedMediaTypeError

An UnsupportedMediaTypeError.

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

detail string

Description of why the media type is not supported.

code string

Custom error code to use instead of the default "unsupported.media.type.error".

instance string

Optional 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

detail string

Description of why the media type is not supported.

instance TInstance

Optional identifier for the resource.

Returns

UnsupportedMediaTypeError

An UnsupportedMediaTypeError.

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

fieldDetails ImmutableArray<ValidationError.FieldError>

Collection of field-specific validation errors.

detail string

Overall error description.

instance string

Optional 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

fieldDetails ImmutableArray<ValidationError.FieldError>

Collection of field-specific validation errors.

detail string

Overall error description.

instance string

Optional identifier for the instance being validated.

code string

Custom 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

fieldDetail string

Description of what's wrong with the field value.

fieldName string

Name of the field that failed validation. Empty string if not field-specific.

detail string

Optional overall error detail. If null, uses fieldDetail.

instance string

Optional 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")