mirror of
https://github.com/flarum/core.git
synced 2025-10-12 15:34:26 +02:00
Split up HandleErrors middleware into distinct classes
These are completely distinct functionalities, toggled through the system-wide debug flag. By moving the selection of the middleware to use to the place where the middleware pipe is built, we make the middleware itself be unaware of these flags. The two classes are more focused on what they are doing, with the constructor dependencies clearly representing their requirements. In addition, this means we can just use the HandleErrorsWithWhoops middleware in the installer, which means we do not need to worry about how to inject a SettingsRepositoryInterface implementation when flarum is not yet set up.
This commit is contained in:
@@ -17,7 +17,8 @@ use Flarum\Foundation\AbstractServiceProvider;
|
||||
use Flarum\Frontend\RecompileFrontendAssets;
|
||||
use Flarum\Http\Middleware\AuthenticateWithSession;
|
||||
use Flarum\Http\Middleware\DispatchRoute;
|
||||
use Flarum\Http\Middleware\HandleErrors;
|
||||
use Flarum\Http\Middleware\HandleErrorsWithView;
|
||||
use Flarum\Http\Middleware\HandleErrorsWithWhoops;
|
||||
use Flarum\Http\Middleware\ParseJsonBody;
|
||||
use Flarum\Http\Middleware\RememberFromCookie;
|
||||
use Flarum\Http\Middleware\SetLocale;
|
||||
@@ -46,8 +47,11 @@ class AdminServiceProvider extends AbstractServiceProvider
|
||||
$pipe = new MiddlewarePipe;
|
||||
|
||||
// All requests should first be piped through our global error handler
|
||||
$debugMode = ! $app->isUpToDate() || $app->inDebugMode();
|
||||
$pipe->pipe($app->make(HandleErrors::class, ['debug' => $debugMode]));
|
||||
if ($app->inDebugMode()) {
|
||||
$pipe->pipe($app->make(HandleErrorsWithWhoops::class));
|
||||
} else {
|
||||
$pipe->pipe($app->make(HandleErrorsWithView::class));
|
||||
}
|
||||
|
||||
$pipe->pipe($app->make(ParseJsonBody::class));
|
||||
$pipe->pipe($app->make(StartSession::class));
|
||||
|
Reference in New Issue
Block a user