Skip to content

Commit 1b37e80

Browse files
authored
Fixed error message for connection exceptions (#68)
* Fixed message for connection exceptions * Unnecessary class import deleted * Fixed PHP 8.1 version
1 parent bba08cf commit 1b37e80

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
}
1212
],
1313
"require": {
14-
"php": "^7.4|^8.0|8.1.*",
14+
"php": "^7.4|^8.0|^8.1",
1515
"ext-curl": "*",
1616
"ext-json": "*",
1717
"guzzlehttp/guzzle": "^7.0",

src/Exception/ExceptionMap.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace FlixTech\SchemaRegistryApi\Exception;
66

77
use Exception;
8+
use GuzzleHttp\Exception\GuzzleException;
89
use GuzzleHttp\Exception\RequestException;
910
use Psr\Http\Message\ResponseInterface;
1011
use RuntimeException;
@@ -38,14 +39,18 @@ private function __construct()
3839
/**
3940
* Maps a RequestException to the internal SchemaRegistryException types.
4041
*
41-
* @param RequestException $exception
42+
* @param GuzzleException $exception
4243
*
4344
* @return SchemaRegistryException
4445
*
4546
* @throws RuntimeException
4647
*/
47-
public function __invoke(RequestException $exception): SchemaRegistryException
48+
public function __invoke(GuzzleException $exception): SchemaRegistryException
4849
{
50+
if (!$exception instanceof RequestException) {
51+
throw $exception;
52+
}
53+
4954
$response = $this->guardAgainstMissingResponse($exception);
5055
$decodedBody = $this->guardAgainstMissingErrorCode($response);
5156
$errorCode = $decodedBody[self::ERROR_CODE_FIELD_NAME];

src/Registry/PromisingRegistry.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use FlixTech\SchemaRegistryApi\Exception\ExceptionMap;
1111
use FlixTech\SchemaRegistryApi\Schema\AvroReference;
1212
use GuzzleHttp\ClientInterface;
13-
use GuzzleHttp\Exception\RequestException;
13+
use GuzzleHttp\Exception\GuzzleException;
1414
use GuzzleHttp\Promise\PromiseInterface;
1515
use InvalidArgumentException;
1616
use Psr\Http\Message\RequestInterface;
@@ -45,7 +45,7 @@ public function __construct(ClientInterface $client)
4545
$this->client = $client;
4646
$exceptionMap = ExceptionMap::instance();
4747

48-
$this->rejectedCallback = static function (RequestException $exception) use ($exceptionMap) {
48+
$this->rejectedCallback = static function (GuzzleException $exception) use ($exceptionMap) {
4949
return $exceptionMap($exception);
5050
};
5151
}

0 commit comments

Comments
 (0)