Closed matteocontrini closed 4 years ago
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.
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.