mirror of
https://github.com/flarum/core.git
synced 2025-07-26 03:01:22 +02:00
Update Client.php (#1198)
* Update Client.php Now forwarding exceptions from client to page in case debug mode is on. Fixes #1120. * Update Client.php Satisfying .. the unsatisfiable. * Update Client.php Satisfying again.
This commit is contained in:
committed by
Franz Liedke
parent
204dedb59b
commit
34af095b2a
@@ -13,30 +13,29 @@ namespace Flarum\Api;
|
|||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Flarum\Core\User;
|
use Flarum\Core\User;
|
||||||
|
use Flarum\Foundation\Application;
|
||||||
use Flarum\Http\Controller\ControllerInterface;
|
use Flarum\Http\Controller\ControllerInterface;
|
||||||
use Illuminate\Contracts\Container\Container;
|
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use Zend\Diactoros\ServerRequestFactory;
|
use Zend\Diactoros\ServerRequestFactory;
|
||||||
|
|
||||||
class Client
|
class Client
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var Container
|
|
||||||
*/
|
|
||||||
protected $container;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ErrorHandler
|
* @var ErrorHandler
|
||||||
*/
|
*/
|
||||||
protected $errorHandler;
|
protected $errorHandler;
|
||||||
|
/**
|
||||||
|
* @var Application
|
||||||
|
*/
|
||||||
|
private $app;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Container $container
|
* @param Application $app
|
||||||
* @param ErrorHandler $errorHandler
|
* @param ErrorHandler $errorHandler
|
||||||
*/
|
*/
|
||||||
public function __construct(Container $container, ErrorHandler $errorHandler)
|
public function __construct(Application $app, ErrorHandler $errorHandler)
|
||||||
{
|
{
|
||||||
$this->container = $container;
|
$this->app = $app;
|
||||||
$this->errorHandler = $errorHandler;
|
$this->errorHandler = $errorHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,6 +47,7 @@ class Client
|
|||||||
* @param array $queryParams
|
* @param array $queryParams
|
||||||
* @param array $body
|
* @param array $body
|
||||||
* @return \Psr\Http\Message\ResponseInterface
|
* @return \Psr\Http\Message\ResponseInterface
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function send($controller, $actor, array $queryParams = [], array $body = [])
|
public function send($controller, $actor, array $queryParams = [], array $body = [])
|
||||||
{
|
{
|
||||||
@@ -56,7 +56,7 @@ class Client
|
|||||||
$request = $request->withAttribute('actor', $actor);
|
$request = $request->withAttribute('actor', $actor);
|
||||||
|
|
||||||
if (is_string($controller)) {
|
if (is_string($controller)) {
|
||||||
$controller = $this->container->make($controller);
|
$controller = $this->app->make($controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! ($controller instanceof ControllerInterface)) {
|
if (! ($controller instanceof ControllerInterface)) {
|
||||||
@@ -68,6 +68,10 @@ class Client
|
|||||||
try {
|
try {
|
||||||
return $controller->handle($request);
|
return $controller->handle($request);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
if ($this->app->inDebugMode()) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
|
||||||
return $this->errorHandler->handle($e);
|
return $this->errorHandler->handle($e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user