diff --git a/src/Client.php b/src/Client.php index ded7494..608247b 100644 --- a/src/Client.php +++ b/src/Client.php @@ -51,7 +51,7 @@ public static function createWithConfig(array $config) */ public function sendRequest(RequestInterface $request) { - $promise = $this->sendAsyncRequest($request); + $promise = $this->sendAsyncRequest($request)->wait(); return $promise->wait(); } diff --git a/src/Promise.php b/src/Promise.php index 4d5eb8d..49ff0e0 100644 --- a/src/Promise.php +++ b/src/Promise.php @@ -95,11 +95,11 @@ public function wait($unwrap = true) $this->promise->wait(false); if ($unwrap) { - if ($this->getState() == self::REJECTED) { - throw $this->exception; + if (self::REJECTED == $this->getState()) { + return \GuzzleHttp\Promise\rejection_for($this->exception); } - return $this->response; + return \GuzzleHttp\Promise\promise_for($this->response); } } diff --git a/tests/PromiseTest.php b/tests/PromiseTest.php index 9803e18..28d3cdb 100644 --- a/tests/PromiseTest.php +++ b/tests/PromiseTest.php @@ -21,6 +21,6 @@ public function testNonDomainExceptionIsHandled() $guzzlePromise = new Promise($promise, $request->reveal()); - $guzzlePromise->wait(); + $guzzlePromise->wait()->wait(); } }