Esempio n. 1
0
 /**
  * @param Exception $e
  * @return JsonApiResponse
  */
 public function handle(Exception $e)
 {
     $response = $this->errorHandler->handle($e);
     $document = new Document();
     $document->setErrors($response->getErrors());
     return new JsonApiResponse($document, $response->getStatus());
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function register()
 {
     $this->app->singleton(UrlGenerator::class, function () {
         return new UrlGenerator($this->app, $this->app->make('flarum.api.routes'));
     });
     $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;
     });
 }
Esempio n. 3
0
 public function test_it_should_throw_an_exception_when_no_handlers_are_present()
 {
     $this->setExpectedException('RuntimeException');
     $handler = new ErrorHandler();
     $handler->handle(new Exception());
 }