The ControllerBase
class has this very handy Problem
method that automatically generates RFC7807 error responses. We just have to specify the title and the status code and the Problem
method will fill in the rest (E.G. Type = URI reference [RFC3986]).
Now, I am designing a global exception filter that will return error responses based on the exception encountered. But I also want to generate errors in the RFC7807 format. By itself, the ProblemDetails
type cannot generate values on its own. I would like to be able to just provide the Title and status code and not care about other values. I will not be able to use ControllerBase.Problem
since errors might occur even before controllers are created.
Is there a way to automatically generate a ProblemDetails
object inside and exception filter? I am using ASP.NET Core 6.0.