Unify generic frontend/backend exception handler API
Describe the bug
Currently rx.App accepts frontend_exception_handler and backend_exception_handler to customize how the app responds to uncaught exceptions.
There are a few problems:
- The exception handler has no way of accessing the state of the client that caused the exception
- The exception handler chaining other events is inconsistent (frontend never, backend only when caught in State -- not when caught in App)
Expected behavior
frontend_exception_handler and backend_exception_handler may either be a plain function (with existing validation) or an EventHandler / EventSpec.
If an EventHandler / EventSpec is provided, it will be processed directly in the same event context as the original exception, using State.process. The state associated with the event handler and the token will be used. Any updates will be yielded to the frontend including chained events.
If a plain function is used, it must NOT return anything. Chaining will no longer be permitted from plain functions. If you want to chain, then you must pass an EventHandler -- this will raise a warning until 0.8.0 for backend handlers.
Specifics (please complete the following information):
- Python Version: 3.13
- Reflex Version: 0.7.8
It would be great if this exception handler could integrate with posthog of all our apps
https://posthog.com/docs/error-tracking/installation?tab=FastAPI