diff --git a/src/Admin/AdminServiceProvider.php b/src/Admin/AdminServiceProvider.php index 3420885d8..16c7857d0 100644 --- a/src/Admin/AdminServiceProvider.php +++ b/src/Admin/AdminServiceProvider.php @@ -14,6 +14,10 @@ use Flarum\Extension\Event\Disabled; use Flarum\Extension\Event\Enabled; use Flarum\Foundation\AbstractServiceProvider; use Flarum\Foundation\Application; +use Flarum\Foundation\ErrorHandling\Registry; +use Flarum\Foundation\ErrorHandling\Reporter; +use Flarum\Foundation\ErrorHandling\ViewRenderer; +use Flarum\Foundation\ErrorHandling\WhoopsRenderer; use Flarum\Foundation\Event\ClearingCache; use Flarum\Frontend\AddLocaleAssets; use Flarum\Frontend\AddTranslations; @@ -49,11 +53,11 @@ class AdminServiceProvider extends AbstractServiceProvider $pipe = new MiddlewarePipe; // All requests should first be piped through our global error handler - if ($app->inDebugMode()) { - $pipe->pipe($app->make(HttpMiddleware\HandleErrorsWithWhoops::class)); - } else { - $pipe->pipe($app->make(HttpMiddleware\HandleErrorsWithView::class)); - } + $pipe->pipe(new HttpMiddleware\HandleErrors( + $app->make(Registry::class), + $app->inDebugMode() ? $app->make(WhoopsRenderer::class) : $app->make(ViewRenderer::class), + $app->make(Reporter::class) + )); $pipe->pipe($app->make(HttpMiddleware\ParseJsonBody::class)); $pipe->pipe($app->make(HttpMiddleware\StartSession::class)); diff --git a/src/Api/ApiServiceProvider.php b/src/Api/ApiServiceProvider.php index 5d946b68f..bd765596c 100644 --- a/src/Api/ApiServiceProvider.php +++ b/src/Api/ApiServiceProvider.php @@ -18,12 +18,13 @@ use Flarum\Event\ConfigureMiddleware; use Flarum\Event\ConfigureNotificationTypes; use Flarum\Foundation\AbstractServiceProvider; use Flarum\Foundation\Application; +use Flarum\Foundation\ErrorHandling\JsonApiRenderer; +use Flarum\Foundation\ErrorHandling\Registry; +use Flarum\Foundation\ErrorHandling\Reporter; use Flarum\Http\Middleware as HttpMiddleware; use Flarum\Http\RouteCollection; use Flarum\Http\RouteHandlerFactory; use Flarum\Http\UrlGenerator; -use Tobscure\JsonApi\ErrorHandler; -use Tobscure\JsonApi\Exception\Handler\InvalidParameterExceptionHandler; use Zend\Stratigility\MiddlewarePipe; class ApiServiceProvider extends AbstractServiceProvider @@ -47,7 +48,11 @@ class ApiServiceProvider extends AbstractServiceProvider $this->app->singleton('flarum.api.middleware', function (Application $app) { $pipe = new MiddlewarePipe; - $pipe->pipe($app->make(Middleware\HandleErrors::class)); + $pipe->pipe(new HttpMiddleware\HandleErrors( + $app->make(Registry::class), + $app->make(JsonApiRenderer::class), + $app->make(Reporter::class) + )); $pipe->pipe($app->make(HttpMiddleware\ParseJsonBody::class)); $pipe->pipe($app->make(Middleware\FakeHttpMethods::class)); @@ -66,25 +71,6 @@ class ApiServiceProvider extends AbstractServiceProvider $this->app->afterResolving('flarum.api.middleware', function (MiddlewarePipe $pipe) { $pipe->pipe(new HttpMiddleware\DispatchRoute($this->app->make('flarum.api.routes'))); }); - - $this->app->singleton(ErrorHandler::class, function () { - $handler = new ErrorHandler; - - $handler->registerHandler(new ExceptionHandler\FloodingExceptionHandler); - $handler->registerHandler(new ExceptionHandler\IlluminateValidationExceptionHandler); - $handler->registerHandler(new ExceptionHandler\InvalidAccessTokenExceptionHandler); - $handler->registerHandler(new ExceptionHandler\InvalidConfirmationTokenExceptionHandler); - $handler->registerHandler(new ExceptionHandler\MethodNotAllowedExceptionHandler); - $handler->registerHandler(new ExceptionHandler\ModelNotFoundExceptionHandler); - $handler->registerHandler(new ExceptionHandler\PermissionDeniedExceptionHandler); - $handler->registerHandler(new ExceptionHandler\RouteNotFoundExceptionHandler); - $handler->registerHandler(new ExceptionHandler\TokenMismatchExceptionHandler); - $handler->registerHandler(new ExceptionHandler\ValidationExceptionHandler); - $handler->registerHandler(new InvalidParameterExceptionHandler); - $handler->registerHandler(new ExceptionHandler\FallbackExceptionHandler($this->app->inDebugMode(), $this->app->make('log'))); - - return $handler; - }); } /** diff --git a/src/Forum/ForumServiceProvider.php b/src/Forum/ForumServiceProvider.php index b93d0988a..1c16b56ed 100644 --- a/src/Forum/ForumServiceProvider.php +++ b/src/Forum/ForumServiceProvider.php @@ -16,6 +16,10 @@ use Flarum\Extension\Event\Enabled; use Flarum\Formatter\Formatter; use Flarum\Foundation\AbstractServiceProvider; use Flarum\Foundation\Application; +use Flarum\Foundation\ErrorHandling\Registry; +use Flarum\Foundation\ErrorHandling\Reporter; +use Flarum\Foundation\ErrorHandling\ViewRenderer; +use Flarum\Foundation\ErrorHandling\WhoopsRenderer; use Flarum\Foundation\Event\ClearingCache; use Flarum\Frontend\AddLocaleAssets; use Flarum\Frontend\AddTranslations; @@ -59,11 +63,11 @@ class ForumServiceProvider extends AbstractServiceProvider $pipe = new MiddlewarePipe; // All requests should first be piped through our global error handler - if ($app->inDebugMode()) { - $pipe->pipe($app->make(HttpMiddleware\HandleErrorsWithWhoops::class)); - } else { - $pipe->pipe($app->make(HttpMiddleware\HandleErrorsWithView::class)); - } + $pipe->pipe(new HttpMiddleware\HandleErrors( + $app->make(Registry::class), + $app->inDebugMode() ? $app->make(WhoopsRenderer::class) : $app->make(ViewRenderer::class), + $app->make(Reporter::class) + )); $pipe->pipe($app->make(HttpMiddleware\ParseJsonBody::class)); $pipe->pipe($app->make(HttpMiddleware\CollectGarbage::class)); diff --git a/src/Install/Installer.php b/src/Install/Installer.php index 0af91a92e..6ac50539e 100644 --- a/src/Install/Installer.php +++ b/src/Install/Installer.php @@ -10,8 +10,11 @@ namespace Flarum\Install; use Flarum\Foundation\AppInterface; +use Flarum\Foundation\ErrorHandling\Registry; +use Flarum\Foundation\ErrorHandling\Reporter; +use Flarum\Foundation\ErrorHandling\WhoopsRenderer; use Flarum\Http\Middleware\DispatchRoute; -use Flarum\Http\Middleware\HandleErrorsWithWhoops; +use Flarum\Http\Middleware\HandleErrors; use Flarum\Http\Middleware\StartSession; use Flarum\Install\Console\InstallCommand; use Illuminate\Contracts\Container\Container; @@ -35,7 +38,11 @@ class Installer implements AppInterface public function getRequestHandler() { $pipe = new MiddlewarePipe; - $pipe->pipe($this->container->make(HandleErrorsWithWhoops::class)); + $pipe->pipe(new HandleErrors( + $this->container->make(Registry::class), + $this->container->make(WhoopsRenderer::class), + $this->container->make(Reporter::class) + )); $pipe->pipe($this->container->make(StartSession::class)); $pipe->pipe( new DispatchRoute($this->container->make('flarum.install.routes'))