mirror of
https://github.com/flarum/framework.git
synced 2025-02-22 12:52:11 +08:00
Use new error handler middleware
This commit is contained in:
parent
cfbaa84fbc
commit
57ce25301d
@ -16,6 +16,10 @@ use Flarum\Extension\Event\Disabled;
|
|||||||
use Flarum\Extension\Event\Enabled;
|
use Flarum\Extension\Event\Enabled;
|
||||||
use Flarum\Foundation\AbstractServiceProvider;
|
use Flarum\Foundation\AbstractServiceProvider;
|
||||||
use Flarum\Foundation\Application;
|
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\Foundation\Event\ClearingCache;
|
||||||
use Flarum\Frontend\AddLocaleAssets;
|
use Flarum\Frontend\AddLocaleAssets;
|
||||||
use Flarum\Frontend\AddTranslations;
|
use Flarum\Frontend\AddTranslations;
|
||||||
@ -51,11 +55,11 @@ class AdminServiceProvider extends AbstractServiceProvider
|
|||||||
$pipe = new MiddlewarePipe;
|
$pipe = new MiddlewarePipe;
|
||||||
|
|
||||||
// All requests should first be piped through our global error handler
|
// All requests should first be piped through our global error handler
|
||||||
if ($app->inDebugMode()) {
|
$pipe->pipe(new HttpMiddleware\HandleErrors(
|
||||||
$pipe->pipe($app->make(HttpMiddleware\HandleErrorsWithWhoops::class));
|
$app->make(Registry::class),
|
||||||
} else {
|
$app->inDebugMode() ? $app->make(WhoopsRenderer::class) : $app->make(ViewRenderer::class),
|
||||||
$pipe->pipe($app->make(HttpMiddleware\HandleErrorsWithView::class));
|
$app->make(Reporter::class)
|
||||||
}
|
));
|
||||||
|
|
||||||
$pipe->pipe($app->make(HttpMiddleware\ParseJsonBody::class));
|
$pipe->pipe($app->make(HttpMiddleware\ParseJsonBody::class));
|
||||||
$pipe->pipe($app->make(HttpMiddleware\StartSession::class));
|
$pipe->pipe($app->make(HttpMiddleware\StartSession::class));
|
||||||
|
@ -20,12 +20,13 @@ use Flarum\Event\ConfigureMiddleware;
|
|||||||
use Flarum\Event\ConfigureNotificationTypes;
|
use Flarum\Event\ConfigureNotificationTypes;
|
||||||
use Flarum\Foundation\AbstractServiceProvider;
|
use Flarum\Foundation\AbstractServiceProvider;
|
||||||
use Flarum\Foundation\Application;
|
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\Middleware as HttpMiddleware;
|
||||||
use Flarum\Http\RouteCollection;
|
use Flarum\Http\RouteCollection;
|
||||||
use Flarum\Http\RouteHandlerFactory;
|
use Flarum\Http\RouteHandlerFactory;
|
||||||
use Flarum\Http\UrlGenerator;
|
use Flarum\Http\UrlGenerator;
|
||||||
use Tobscure\JsonApi\ErrorHandler;
|
|
||||||
use Tobscure\JsonApi\Exception\Handler\InvalidParameterExceptionHandler;
|
|
||||||
use Zend\Stratigility\MiddlewarePipe;
|
use Zend\Stratigility\MiddlewarePipe;
|
||||||
|
|
||||||
class ApiServiceProvider extends AbstractServiceProvider
|
class ApiServiceProvider extends AbstractServiceProvider
|
||||||
@ -49,7 +50,11 @@ class ApiServiceProvider extends AbstractServiceProvider
|
|||||||
$this->app->singleton('flarum.api.middleware', function (Application $app) {
|
$this->app->singleton('flarum.api.middleware', function (Application $app) {
|
||||||
$pipe = new MiddlewarePipe;
|
$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(HttpMiddleware\ParseJsonBody::class));
|
||||||
$pipe->pipe($app->make(Middleware\FakeHttpMethods::class));
|
$pipe->pipe($app->make(Middleware\FakeHttpMethods::class));
|
||||||
@ -68,25 +73,6 @@ class ApiServiceProvider extends AbstractServiceProvider
|
|||||||
$this->app->afterResolving('flarum.api.middleware', function (MiddlewarePipe $pipe) {
|
$this->app->afterResolving('flarum.api.middleware', function (MiddlewarePipe $pipe) {
|
||||||
$pipe->pipe(new HttpMiddleware\DispatchRoute($this->app->make('flarum.api.routes')));
|
$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;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,6 +18,10 @@ use Flarum\Extension\Event\Enabled;
|
|||||||
use Flarum\Formatter\Formatter;
|
use Flarum\Formatter\Formatter;
|
||||||
use Flarum\Foundation\AbstractServiceProvider;
|
use Flarum\Foundation\AbstractServiceProvider;
|
||||||
use Flarum\Foundation\Application;
|
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\Foundation\Event\ClearingCache;
|
||||||
use Flarum\Frontend\AddLocaleAssets;
|
use Flarum\Frontend\AddLocaleAssets;
|
||||||
use Flarum\Frontend\AddTranslations;
|
use Flarum\Frontend\AddTranslations;
|
||||||
@ -61,11 +65,11 @@ class ForumServiceProvider extends AbstractServiceProvider
|
|||||||
$pipe = new MiddlewarePipe;
|
$pipe = new MiddlewarePipe;
|
||||||
|
|
||||||
// All requests should first be piped through our global error handler
|
// All requests should first be piped through our global error handler
|
||||||
if ($app->inDebugMode()) {
|
$pipe->pipe(new HttpMiddleware\HandleErrors(
|
||||||
$pipe->pipe($app->make(HttpMiddleware\HandleErrorsWithWhoops::class));
|
$app->make(Registry::class),
|
||||||
} else {
|
$app->inDebugMode() ? $app->make(WhoopsRenderer::class) : $app->make(ViewRenderer::class),
|
||||||
$pipe->pipe($app->make(HttpMiddleware\HandleErrorsWithView::class));
|
$app->make(Reporter::class)
|
||||||
}
|
));
|
||||||
|
|
||||||
$pipe->pipe($app->make(HttpMiddleware\ParseJsonBody::class));
|
$pipe->pipe($app->make(HttpMiddleware\ParseJsonBody::class));
|
||||||
$pipe->pipe($app->make(HttpMiddleware\CollectGarbage::class));
|
$pipe->pipe($app->make(HttpMiddleware\CollectGarbage::class));
|
||||||
|
@ -12,8 +12,11 @@
|
|||||||
namespace Flarum\Install;
|
namespace Flarum\Install;
|
||||||
|
|
||||||
use Flarum\Foundation\AppInterface;
|
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\DispatchRoute;
|
||||||
use Flarum\Http\Middleware\HandleErrorsWithWhoops;
|
use Flarum\Http\Middleware\HandleErrors;
|
||||||
use Flarum\Http\Middleware\StartSession;
|
use Flarum\Http\Middleware\StartSession;
|
||||||
use Flarum\Install\Console\InstallCommand;
|
use Flarum\Install\Console\InstallCommand;
|
||||||
use Illuminate\Contracts\Container\Container;
|
use Illuminate\Contracts\Container\Container;
|
||||||
@ -37,7 +40,11 @@ class Installer implements AppInterface
|
|||||||
public function getRequestHandler()
|
public function getRequestHandler()
|
||||||
{
|
{
|
||||||
$pipe = new MiddlewarePipe;
|
$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($this->container->make(StartSession::class));
|
||||||
$pipe->pipe(
|
$pipe->pipe(
|
||||||
new DispatchRoute($this->container->make('flarum.install.routes'))
|
new DispatchRoute($this->container->make('flarum.install.routes'))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user