diff --git a/src/Api/ApiServiceProvider.php b/src/Api/ApiServiceProvider.php index d83f7cafc..6cf681320 100644 --- a/src/Api/ApiServiceProvider.php +++ b/src/Api/ApiServiceProvider.php @@ -74,6 +74,7 @@ class ApiServiceProvider extends AbstractServiceProvider $this->container->bind('flarum.api.error_handler', function () { $jsonFormatter = new JsonApiFormatter($this->container['flarum.config']->inDebugMode()); + return new HttpMiddleware\HandleErrors( $this->container->make(Registry::class), $jsonFormatter, diff --git a/src/Forum/ForumServiceProvider.php b/src/Forum/ForumServiceProvider.php index 877b35cb5..9b4320943 100644 --- a/src/Forum/ForumServiceProvider.php +++ b/src/Forum/ForumServiceProvider.php @@ -35,7 +35,6 @@ use Flarum\Settings\Event\Saving; use Flarum\Settings\SettingsRepositoryInterface; use Laminas\Stratigility\MiddlewarePipe; use Laminas\Stratigility\MiddlewarePipeInterface; -use Psr\Http\Server\MiddlewareInterface; use Symfony\Contracts\Translation\TranslatorInterface; class ForumServiceProvider extends AbstractServiceProvider @@ -132,13 +131,13 @@ class ForumServiceProvider extends AbstractServiceProvider $this->container->when(FrontendFormatter::class) ->needs(MiddlewarePipeInterface::class) - ->give(function() { + ->give(function () { $middleware = $this->container->make('flarum.forum.middleware'); $pipe = new MiddlewarePipe; foreach ($middleware as $middlewareClass) { - if (!in_array($middlewareClass, [ + if (! in_array($middlewareClass, [ 'flarum.forum.error_handler', HttpMiddleware\InjectActorReference::class, HttpMiddleware\RememberFromCookie::class, diff --git a/src/Foundation/ErrorHandling/Middleware/ExecuteErrorToFrontend.php b/src/Foundation/ErrorHandling/Middleware/ExecuteErrorToFrontend.php index d6c3e76bd..f943ef250 100644 --- a/src/Foundation/ErrorHandling/Middleware/ExecuteErrorToFrontend.php +++ b/src/Foundation/ErrorHandling/Middleware/ExecuteErrorToFrontend.php @@ -1,5 +1,12 @@ frontend = $frontend; $this->handlerFactory = $handlerFactory; } @@ -34,4 +42,4 @@ class ExecuteErrorToFrontend implements MiddlewareInterface return $controller($request, [])->withStatus($error->getStatusCode()); } -} \ No newline at end of file +} diff --git a/src/Foundation/ErrorHandling/Registry.php b/src/Foundation/ErrorHandling/Registry.php index c2526df6a..8d88a9b02 100644 --- a/src/Foundation/ErrorHandling/Registry.php +++ b/src/Foundation/ErrorHandling/Registry.php @@ -66,7 +66,7 @@ class Registry $errorType = $this->classMap[$errorClass]; } } - + $errorContent = Arr::get($this->contentMap, $errorClass); if ($errorType) { diff --git a/src/Http/HttpServiceProvider.php b/src/Http/HttpServiceProvider.php index 157b1bcf2..343b67576 100644 --- a/src/Http/HttpServiceProvider.php +++ b/src/Http/HttpServiceProvider.php @@ -12,17 +12,9 @@ namespace Flarum\Http; use Flarum\Discussion\Discussion; use Flarum\Discussion\IdWithTransliteratedSlugDriver; use Flarum\Foundation\AbstractServiceProvider; -use Flarum\Foundation\ErrorHandling\FrontendFormatter; -use Flarum\Foundation\ErrorHandling\Registry; -use Flarum\Foundation\ErrorHandling\Reporter; -use Flarum\Foundation\ErrorHandling\WhoopsFormatter; -use Flarum\Http\Exception\RouteNotFoundException; use Flarum\Settings\SettingsRepositoryInterface; -use Flarum\User\Exception\NotAuthenticatedException; -use Flarum\User\Exception\PermissionDeniedException; use Flarum\User\User; use Flarum\User\UsernameSlugDriver; -use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Support\Arr; class HttpServiceProvider extends AbstractServiceProvider