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 |
|---|---|
| Error.UnprocessableContent | 422 Unprocessable Entity |
| Error.BadRequest | 400 Bad Request |
| Error.Unauthorized | 401 Unauthorized |
| Error.Forbidden | 403 Forbidden |
| Error.NotFound | 404 Not Found |
| Error.Conflict | 409 Conflict |
| Error.PreconditionFailed | 412 Precondition Failed |
| Error.PreconditionRequired | 428 Precondition Required |
| Error.TooManyRequests | 429 Too Many Requests |
| Error.InternalServerError | 500 Internal Server Error |
| Error.Unexpected | 500 Internal Server Error |
| Error.ServiceUnavailable | 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<Error.Conflict>(StatusCodes.Status400BadRequest)
.MapError<Error.UnprocessableContent>(StatusCodes.Status422UnprocessableEntity);