1
0
mirror of https://github.com/flarum/core.git synced 2025-08-01 22:20:21 +02:00

Use exception handlers instead of JsonApiSerializableInterface

This commit is contained in:
Toby Zerner
2015-10-26 11:12:10 +10:30
parent f3612261ec
commit 68498cedae
14 changed files with 326 additions and 141 deletions

View File

@@ -18,7 +18,9 @@ use Flarum\Event\ConfigureNotificationTypes;
use Flarum\Http\GenerateRouteHandlerTrait;
use Flarum\Http\RouteCollection;
use Flarum\Foundation\AbstractServiceProvider;
use Psr\Http\Message\ServerRequestInterface;
use Tobscure\JsonApi\ErrorHandler;
use Tobscure\JsonApi\Exception\Handler\FallbackExceptionHandler;
use Tobscure\JsonApi\Exception\Handler\InvalidParameterExceptionHandler;
class ApiServiceProvider extends AbstractServiceProvider
{
@@ -36,6 +38,21 @@ class ApiServiceProvider extends AbstractServiceProvider
$this->app->singleton('flarum.api.routes', function () {
return $this->getRoutes();
});
$this->app->singleton(ErrorHandler::class, function () {
$handler = new ErrorHandler;
$handler->registerHandler(new Handler\FloodingExceptionHandler);
$handler->registerHandler(new Handler\IlluminateValidationExceptionHandler);
$handler->registerHandler(new Handler\InvalidConfirmationTokenExceptionHandler);
$handler->registerHandler(new Handler\ModelNotFoundExceptionHandler);
$handler->registerHandler(new Handler\PermissionDeniedExceptionHandler);
$handler->registerHandler(new Handler\ValidationExceptionHandler);
$handler->registerHandler(new InvalidParameterExceptionHandler);
$handler->registerHandler(new FallbackExceptionHandler($this->app->inDebugMode()));
return $handler;
});
}
/**