Skip to content

Commit

Permalink
Pass the transfer exception through as "previous" (#13)
Browse files Browse the repository at this point in the history
- Provides access to server response to help identify errors
  • Loading branch information
jsandersuk authored and rccrdpccl committed May 9, 2018
1 parent 795b54b commit 2a25cf4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function query(string $query, array $variables = []): Response
try {
$response = $this->httpClient->request('POST', '', $options);
} catch (TransferException $e) {
throw new \RuntimeException('Network Error.');
throw new \RuntimeException('Network Error.'.$e->getMessage(), 0, $e);
}

return $this->responseBuilder->build($response);
Expand Down
22 changes: 22 additions & 0 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,28 @@ public function testSimpleQueryWhenHasNetworkErrors()
$this->client->query($query);
}

public function testCanRetrievePreviousExceptionWhenSimpleQueryHasErrors()
{
$previousException = null;
try {
$originalException = new \GuzzleHttp\Exception\ServerException(
'Server side error',
$this->createMock(\Psr\Http\Message\RequestInterface::class)
);

$this->httpClient->expects($this->once())
->method('request')
->willThrowException($originalException);

$query = $this->getSimpleQuery();
$this->client->query($query);
} catch (\Exception $e) {
$previousException = $e->getPrevious();
} finally {
$this->assertSame($originalException, $previousException);
}
}

public function testSimpleQueryWhenInvalidJsonIsReceived()
{
$query = $this->getSimpleQuery();
Expand Down

0 comments on commit 2a25cf4

Please sign in to comment.