diff --git a/framework/core/src/Api/Client.php b/framework/core/src/Api/Client.php index 4e23bf5a1..bf6d2b264 100644 --- a/framework/core/src/Api/Client.php +++ b/framework/core/src/Api/Client.php @@ -14,6 +14,7 @@ namespace Flarum\Api; use Exception; use Flarum\Foundation\Application; use Flarum\User\User; +use Illuminate\Contracts\Container\Container; use InvalidArgumentException; use Psr\Http\Message\ResponseInterface; use Psr\Http\Server\RequestHandlerInterface; @@ -21,22 +22,23 @@ use Zend\Diactoros\ServerRequestFactory; class Client { + /** + * @var Container + */ + protected $container; + /** * @var ErrorHandler */ protected $errorHandler; - /** - * @var Application - */ - private $app; /** - * @param Application $app + * @param Container $container * @param ErrorHandler $errorHandler */ - public function __construct(Application $app, ErrorHandler $errorHandler) + public function __construct(Container $container, ErrorHandler $errorHandler = null) { - $this->app = $app; + $this->container = $container; $this->errorHandler = $errorHandler; } @@ -57,7 +59,7 @@ class Client $request = $request->withAttribute('actor', $actor); if (is_string($controller)) { - $controller = $this->app->make($controller); + $controller = $this->container->make($controller); } if (! ($controller instanceof RequestHandlerInterface)) { @@ -69,11 +71,22 @@ class Client try { return $controller->handle($request); } catch (Exception $e) { - if ($this->app->inDebugMode()) { + if (! $this->errorHandler) { throw $e; } return $this->errorHandler->handle($e); } } + + /** + * @param ErrorHandler $errorHandler + * @return Client + */ + public function setErrorHandler(?ErrorHandler $errorHandler): Client + { + $this->errorHandler = $errorHandler; + + return $this; + } } diff --git a/framework/core/src/Frontend/HtmlDocumentFactory.php b/framework/core/src/Frontend/HtmlDocumentFactory.php index aa8871327..a588e1138 100644 --- a/framework/core/src/Frontend/HtmlDocumentFactory.php +++ b/framework/core/src/Frontend/HtmlDocumentFactory.php @@ -128,6 +128,8 @@ class HtmlDocumentFactory { $actor = $request->getAttribute('actor'); + $this->api->setErrorHandler(null); + return $this->getResponseBody( $this->api->send(ShowForumController::class, $actor) );