Skip to content

Commit ecc170e

Browse files
authored
Fixes #42 - Call to undefined method GuzzleHttp\Exception\ConnectException::getResponse(). (#51)
* Fixes: #42 - Call to undefined method GuzzleHttp\Exception\ConnectException::getResponse().
1 parent d9d95fa commit ecc170e

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/HTTPClient.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,10 @@ public function request(string $method, $uri = '', array $options = [] ): Respon
181181
$response = parent::request( $method, $uri, $options );
182182
}
183183
catch ( \GuzzleHttp\Exception\TransferException $e ) {
184-
$response = $e->getResponse();
184+
if (method_exists($e, 'hasResponse') && $e->hasResponse()) {
185+
return $e->getResponse();
186+
}
187+
throw $e;
185188
}
186189

187190
return $response;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace ZammadAPIClient;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
use ZammadAPIClient\Client;
8+
use GuzzleHttp\Exception\ConnectException;
9+
10+
class ClientTest extends TestCase
11+
{
12+
public function testNetworkError()
13+
{
14+
// When providing a wrong URL, there must be a proper exception thrown.
15+
$this->expectException( \GuzzleHttp\Exception\ConnectException::class );
16+
17+
$client = new Client([
18+
'url' => 'https://non.existing.ci/',
19+
'username' => 'nonexisting',
20+
'password' => 'nonexisting',
21+
]);
22+
$client->get('/nonexisting');
23+
}
24+
}

0 commit comments

Comments
 (0)