Class TrellisAspOptions
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 Type | Default HTTP Status |
|---|---|
| ValidationError | 400 Bad Request |
| BadRequestError | 400 Bad Request |
| UnauthorizedError | 401 Unauthorized |
| ForbiddenError | 403 Forbidden |
| NotFoundError | 404 Not Found |
| ConflictError | 409 Conflict |
| PreconditionFailedError | 412 Precondition Failed |
| PreconditionRequiredError | 428 Precondition Required |
| DomainError | 422 Unprocessable Entity |
| RateLimitError | 429 Too Many Requests |
| UnexpectedError | 500 Internal Server Error |
| ServiceUnavailableError | 503 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
statusCodeintThe HTTP status code to return for this error type.
Returns
- TrellisAspOptions
The options instance for fluent chaining.
Type Parameters
TErrorThe error type to map. Must derive from Error.
Examples
options.MapError<DomainError>(StatusCodes.Status400BadRequest)
.MapError<ConflictError>(StatusCodes.Status422UnprocessableEntity);