Table of Contents

Class TrellisAspOptions

Namespace
Trellis.Asp
Assembly
Trellis.Asp.dll

Configuration options for Trellis ASP.NET Core integration. Controls how domain error types are mapped to HTTP status codes.

public sealed class TrellisAspOptions
Inheritance
TrellisAspOptions
Inherited Members
Extension Methods

Examples

Zero-config — uses defaults:

builder.Services.AddTrellisAsp();

Override specific mappings:

builder.Services.AddTrellisAsp(options =>
{
    options.MapError<DomainError>(StatusCodes.Status400BadRequest);
});

Remarks

By default, all standard error types are mapped to conventional HTTP status codes:

Error TypeDefault HTTP Status
ValidationError400 Bad Request
BadRequestError400 Bad Request
UnauthorizedError401 Unauthorized
ForbiddenError403 Forbidden
NotFoundError404 Not Found
ConflictError409 Conflict
PreconditionFailedError412 Precondition Failed
PreconditionRequiredError428 Precondition Required
DomainError422 Unprocessable Entity
RateLimitError429 Too Many Requests
UnexpectedError500 Internal Server Error
ServiceUnavailableError503 Service Unavailable

Use MapError<TError>(int) to override any mapping. Unmapped error types fall back to 500 Internal Server Error.

Methods

MapError<TError>(int)

Maps an error type to an HTTP status code. Overrides the default mapping if one exists.

public TrellisAspOptions MapError<TError>(int statusCode) where TError : Error

Parameters

statusCode int

The HTTP status code to return for this error type.

Returns

TrellisAspOptions

The options instance for fluent chaining.

Type Parameters

TError

The error type to map. Must derive from Error.

Examples

options.MapError<DomainError>(StatusCodes.Status400BadRequest)
       .MapError<ConflictError>(StatusCodes.Status422UnprocessableEntity);