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
traceId population logic as I cannot call CallBeforeWriteHook as it currently has internal access
To make the library support this scenario:
- Extend
ProblemDetailsOptions to register Result mappers
options.MapResult<BusinessError>((context, result) =>
{
// logic goes here
})
- Make
ProblemDetailsResultFilter to 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);
}
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
ProblemDetailsResultFilterto turn object result intoProblemDetailsduringOnResultExecutingexecution.What I'm currently trying to achieve is to return my own
Errortypes withproblemaction results (as I want to avoid usingexceptionflow where possible) and turn them intoProblemDetailswhen action result is executed, e.g.To achieve that I have to
ProblemDetailstraceIdpopulation logic as I cannot callCallBeforeWriteHookas it currently hasinternalaccessTo make the library support this scenario:
ProblemDetailsOptionsto registerResultmappersProblemDetailsResultFilterto go through registered mappers and execute it if found just like it is currently done for exception mapping, e.g.