mirror of
https://github.com/flarum/core.git
synced 2025-07-29 20:50:28 +02:00
Allow manipulating error handler through extender
By giving each middleware a name, they can now be replaced or moved around using the Middleware extender. Fixes #2115.
This commit is contained in:
@@ -44,6 +44,7 @@ class ApiServiceProvider extends AbstractServiceProvider
|
||||
|
||||
$this->app->singleton('flarum.api.middleware', function () {
|
||||
return [
|
||||
'flarum.api.error_handler',
|
||||
HttpMiddleware\ParseJsonBody::class,
|
||||
Middleware\FakeHttpMethods::class,
|
||||
HttpMiddleware\StartSession::class,
|
||||
@@ -55,14 +56,16 @@ class ApiServiceProvider extends AbstractServiceProvider
|
||||
];
|
||||
});
|
||||
|
||||
$this->app->singleton('flarum.api.handler', function () {
|
||||
$pipe = new MiddlewarePipe;
|
||||
|
||||
$pipe->pipe(new HttpMiddleware\HandleErrors(
|
||||
$this->app->bind('flarum.api.error_handler', function () {
|
||||
return new HttpMiddleware\HandleErrors(
|
||||
$this->app->make(Registry::class),
|
||||
new JsonApiFormatter($this->app['flarum']->inDebugMode()),
|
||||
$this->app->tagged(Reporter::class)
|
||||
));
|
||||
);
|
||||
});
|
||||
|
||||
$this->app->singleton('flarum.api.handler', function () {
|
||||
$pipe = new MiddlewarePipe;
|
||||
|
||||
foreach ($this->app->make('flarum.api.middleware') as $middleware) {
|
||||
$pipe->pipe($this->app->make($middleware));
|
||||
|
Reference in New Issue
Block a user