Custom Mappers and Policy Composition
Use custom mappers when built-in failure mappings are not enough for your API contract.
Add Custom Failure Mappings
using UnambitiousFx.Functional.AspNetCore;
using UnambitiousFx.Functional.AspNetCore.Mappers;
builder.Services.AddResultHttp(options =>
{
options.AddMapper<RateLimitFailure>(429);
options.AddMapper<PaymentRequiredFailure>(failure => new FailureHttpResponse
{
StatusCode = 402,
Body = new { message = failure.Message }
});
});
Configure Policy Defaults
Global behavior can be tuned with adapter policy options, for example:
- Non-generic
Resultsuccess status (200vs204) Maybe.Nonehandling (404vs204)
Composition Guidelines
- Keep domain failures transport-agnostic.
- Map transport semantics in one place (startup/composition root).
- Prefer typed failures over message parsing for deterministic mapping.