-
Notifications
You must be signed in to change notification settings - Fork 107
Open
Description
Hi @khellang
Thank you for your work. I really enjoy using this library.
There's one scenario I'd really love if the library could support: is to allow defining custom action result mappers that will be executed from ProblemDetailsResultFilter to turn object result into ProblemDetails during OnResultExecuting execution.
What I'm currently trying to achieve is to return my own Error types with problem action results (as I want to avoid using exception flow where possible) and turn them into ProblemDetails when action result is executed, e.g.
...
return BadRequest(new BusinessError(ErrorCodes.InsufficientFunds, "some_message);To achieve that I have to
- Define custom result filter to transform value into
ProblemDetails
if (result.Value is BusinessError error)
{
var problem = factory.CreateProblemDetails(context.HttpContext, result.StatusCode, detail: error.Message);
problem.Extensions.Add("errorCode", error.ErrorCode.ToString());
context.Result = new ObjectResult(p)
{
StatusCode = p.Status,
ContentTypes = result.ContentTypes
};
}- Replicate
traceIdpopulation logic as I cannot callCallBeforeWriteHookas it currently hasinternalaccess
To make the library support this scenario:
- Extend
ProblemDetailsOptionsto registerResultmappers
options.MapResult<BusinessError>((context, result) =>
{
// logic goes here
})
- Make
ProblemDetailsResultFilterto go through registered mappers and execute it if found just like it is currently done for exception mapping, e.g.
if (Options.TryMapResult(context, result.Value, out var details))
{
context.Result = CreateResult(context, details);
}Metadata
Metadata
Assignees
Labels
No labels