Make registration errors still work properly when debug mode is on

This commit is contained in:
Toby Zerner 2018-09-21 14:18:17 +09:30
parent 5e1e7b2171
commit 5cda25c8b6
2 changed files with 24 additions and 9 deletions

View File

@ -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;
}
}

View File

@ -128,6 +128,8 @@ class HtmlDocumentFactory
{
$actor = $request->getAttribute('actor');
$this->api->setErrorHandler(null);
return $this->getResponseBody(
$this->api->send(ShowForumController::class, $actor)
);