diff --git a/src/Foundation/ErrorHandling/FrontendFormatter.php b/src/Foundation/ErrorHandling/FrontendFormatter.php index ff02962ba..a8979462d 100644 --- a/src/Foundation/ErrorHandling/FrontendFormatter.php +++ b/src/Foundation/ErrorHandling/FrontendFormatter.php @@ -14,11 +14,8 @@ use Flarum\Frontend\Frontend; use Flarum\Http\Content\NotAuthenticated; use Flarum\Http\Content\NotFound; use Flarum\Http\Content\PermissionDenied; -use Flarum\Settings\SettingsRepositoryInterface; -use Illuminate\Contracts\Container\Container; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; -use Symfony\Component\Translation\TranslatorInterface; /** * This formatter will route certain errors to the SPA frontend. @@ -37,16 +34,14 @@ class FrontendFormatter implements HttpFormatter public function format(HandledError $error, Request $request): Response { - $frontend = $this->container->make('flarum.frontend.forum'); - if ($error->getStatusCode() === 401) { - $frontend->content(new NotAuthenticated); + $this->frontend->content(new NotAuthenticated); } elseif ($error->getStatusCode() === 403) { - $frontend->content(new PermissionDenied); + $this->frontend->content(new PermissionDenied); } elseif ($error->getStatusCode() === 404) { - $frontend->content(new NotFound); + $this->frontend->content(new NotFound); } - return (new Controller($frontend))->handle($request)->withStatus($error->getStatusCode()); + return (new Controller($this->frontend))->handle($request)->withStatus($error->getStatusCode()); } } diff --git a/src/Http/HttpServiceProvider.php b/src/Http/HttpServiceProvider.php index a14c88e18..45ed4e7e9 100644 --- a/src/Http/HttpServiceProvider.php +++ b/src/Http/HttpServiceProvider.php @@ -20,7 +20,6 @@ use Flarum\Foundation\ErrorHandling\FrontendFormatter; use Flarum\Foundation\ErrorHandling\Registry; use Flarum\Foundation\ErrorHandling\Reporter; use Flarum\Foundation\ErrorHandling\WhoopsFormatter; -use Flarum\Frontend\Frontend; use Flarum\Http\Exception\RouteNotFoundException; use Flarum\User\Exception\NotAuthenticatedException; use Flarum\User\Exception\PermissionDeniedException; @@ -84,17 +83,11 @@ class HttpServiceProvider extends AbstractServiceProvider $this->container->singleton('flarum.http.frontend_handler', function () { return new Middleware\HandleErrors( $this->container->make(Registry::class), - $this->container['flarum']->inDebugMode() ? $this->container->make(WhoopsFormatter::class) : $this->container->make(FrontendFormatter::class), + $this->container['flarum']->inDebugMode() ? $this->container->make(WhoopsFormatter::class) : new FrontendFormatter($this->container->make('flarum.frontend.forum')), $this->container->tagged(Reporter::class), $this->container->make('flarum.http.frontend_exceptions') ); }); - - $this->container->when(FrontendFormatter::class) - ->needs(Frontend::class) - ->give(function () { - return $this->container->make('flarum.frontend.forum'); - }); } /**