Closed retendo closed 3 years ago
I got a related question. Is there any way to get the current HttpContext at the top level application CE error_handler? I would like to log information from the context. So far I didn't see any possibility to do so. The reason why I want to do top level exception handling is that I have a mix of controllers and sub routers and while I could do exception handling in controllers, there is no such way in routers.
Could we have the application CE pass the HttpContext to the provided error_handler instead of the logger?
It's very easy to get the logger from from ctx and I could also use ctx.GetLogger
Hi,
I just recognized that the default Controller exception handling is not super useful.
By default, the ErrorHandler in Controllers just does:
Here: https://github.com/SaturnFramework/Saturn/blob/8e2761440841a51d5cf845cf8ba359714867398f/src/Saturn/Controller.fs#L110
This completely erases the original/useful stack trace. It's a problem when you want to do top level exception handling.
There might be better ways as a default:
https://stackoverflow.com/questions/41193629/how-to-keep-the-stacktrace-when-rethrowing-an-exception-out-of-catch-context
Workaround for now:
For each controller, define your own error handler and use one of the methods in the above linked StackOverflow answers