diff --git a/src/Client.php b/src/Client.php index 9e7486cf..37c94510 100644 --- a/src/Client.php +++ b/src/Client.php @@ -249,13 +249,13 @@ class Client implements ClientInterface throw $this->getNoRingResponseException($trans->request); } catch (\Exception $e) { - $this->wrapException($request, $e); + throw $this->wrapException($request, $e); } } private function wrapException(RequestInterface $request, \Exception $e) { - throw $e instanceof RequestException + return $e instanceof RequestException ? $e : new RequestException($e->getMessage(), $request, null, $e); } @@ -274,7 +274,7 @@ class Client implements ClientInterface // Exceptions need to be removed when intercepting errors, // otherwise, they're thrown. if ($trans->exception) { - $this->wrapException($trans->request, $trans->exception); + throw $this->wrapException($trans->request, $trans->exception); } // No exception, so the transaction should have a response. if ($trans->response) { diff --git a/tests/ClientTest.php b/tests/ClientTest.php index f42da078..e7d5af00 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -338,6 +338,19 @@ class ClientTest extends \PHPUnit_Framework_TestCase $client->get('http://httpbin.org'); } + /** + * @expectedException \GuzzleHttp\Exception\RequestException + * @expectedExceptionMessage incorrectly implemented Guzzle Ring adapter + */ + public function testEnsuresResponseIsPresentAfterDereferencing() + { + $adapter = function () { + return new Future(function () { return []; }); + }; + $client = new Client(['adapter' => $adapter]); + $client->get('http://httpbin.org')->deref(); + } + public function testClientHandlesErrorsDuringBeforeSend() { $client = new Client();