map my custom exception to ExceptionProblemDetails
See original GitHub issueHi dears, at first, I read your sample in the GitHub, run it, and fine worked.
but in my real application, I have a Custom exception class that used in the domain layer. this class derived from System.Exception. and has multiple extra property(errorCode, errorMsg, StatusCode).
now I want to map my exception class to ExceptionProblemDetails class when configure the problem detail in ConfigureServices() in the startup.
I know also you map with this code:
options.Map<MyCustomException>(ex => new ExceptionProblemDetails(ex, (int)ex.HttpStatusCode));
can I map my properties to the property of the problem detail class before write response by the ProblemDetailsMiddleware. for example(mapping):
new ProblemDetails() { Title = myCustomException.Code.ToString(), Detail = myCustomException.Message, Status = (int?)myCustomException.HttpStatusCode })
thanks.
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (7 by maintainers)
Top GitHub Comments
Right. That’s because the status code is 400, and we only log 500+ error codes by default. I pushed a new version to NuGet that allows you to set
https://github.com/khellang/Middleware/blob/10d508e1071a86dd59360b0f15760aca0e7d43ba/src/ProblemDetails/ProblemDetailsOptions.cs#L43
when configuring the middleware. It will allow you to tweak when the middleware will log an exception as “unhandled”, as people seem to want different things here.
Example:
Great! Let me know if it works so we can close this issue 👌