-
-
Notifications
You must be signed in to change notification settings - Fork 834
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New PHP Extender: Registering custom exception handler #1781
Comments
Thanks for the detailed report! We basically just need to restructure the binding and then add an Extender for this, similar to how the Frontend extender works. |
The first example that came into mind is fof/sentry. Which adds it own handler as well. It does by adding the handler into the middleware stack. Check: |
Linking this to #1641, which also has to do with exception handling, so the two should probably be handled together. |
#1843 made this very easy, now we just need the extenders. 😄 |
This extender implements several methods for extending the new error handling stack implemented in flarum#1843. Most use-cases should be covered, but I expect some challenges for more complex setups. We can tackle those once they come up, though. Basic use-cases should be covered. Fixes flarum#1781.
Currently, extensions cannot register a custom
ErrorHandler
. For example, an extension cannot throw a custom exception in a controller and also rely on a custom handler to generate an appropriate JSON response.With the following sample, if
MyException
is thrown in a controller the registered error handler is not called.The problem is that the ErrorHandler is configured with a FallbackHandler that catches all the exceptions (line 82), so if you register a new one it will be appended after the fallback one.
https://github.com/flarum/core/blob/bbe62f400fd849f1f86ce7a4931c59fab4aec6fc/src/Api/ApiServiceProvider.php#L68-L85
I'll leave the discussion and proposals for an improvement to actual PHP/Flarum developers 😄
Thanks.
The text was updated successfully, but these errors were encountered: