Add middleware in admin and forum to some errors via the frontend

This commit is contained in:
Alexander Skvortsov 2020-07-28 18:12:51 -04:00
parent f879182ef7
commit 194cf555db
3 changed files with 25 additions and 0 deletions

View File

@ -58,6 +58,7 @@ class AdminServiceProvider extends AbstractServiceProvider
HttpMiddleware\SetLocale::class,
'flarum.admin.route_resolver',
HttpMiddleware\CheckCsrfToken::class,
'flarum.http.frontend_handler',
Middleware\RequireAdministrateAbility::class
];
});

View File

@ -69,6 +69,7 @@ class ForumServiceProvider extends AbstractServiceProvider
'flarum.forum.route_resolver',
HttpMiddleware\CheckCsrfToken::class,
HttpMiddleware\ShareErrorsFromSession::class,
'flarum.http.frontend_handler',
HttpMiddleware\FlarumPromotionHeader::class,
];
});

View File

@ -16,6 +16,10 @@ use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\User\User;
use Flarum\User\UsernameSlugDriver;
use Illuminate\Support\Arr;
use Flarum\Foundation\ErrorHandling\Registry;
use Flarum\Foundation\ErrorHandling\Reporter;
use Flarum\Foundation\ErrorHandling\FrontendFormatter;
use Flarum\Foundation\ErrorHandling\WhoopsFormatter;
class HttpServiceProvider extends AbstractServiceProvider
{
@ -58,9 +62,28 @@ class HttpServiceProvider extends AbstractServiceProvider
return $compiledDrivers;
});
$this->container->bind(SlugManager::class, function () {
return new SlugManager($this->container->make('flarum.http.selectedSlugDrivers'));
});
$this->container->singleton('flarum.http.frontend_exceptions', function () {
return [
NotAuthenticatedException::class, // 401
PermissionDeniedException::class, // 403
ModelNotFoundException::class, // 404
RouteNotFoundException::class, // 404
];
});
$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->tagged(Reporter::class),
$this->container->make('flarum.http.frontend_exceptions')
);
});
}
/**