Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed error message for connection exceptions #68

Merged
merged 5 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}
],
"require": {
"php": "^7.4|^8.0|8.1.*",
"php": "^7.4|^8.0|^8.1",
"ext-curl": "*",
"ext-json": "*",
"guzzlehttp/guzzle": "^7.0",
Expand Down
9 changes: 7 additions & 2 deletions src/Exception/ExceptionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace FlixTech\SchemaRegistryApi\Exception;

use Exception;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\RequestException;
use Psr\Http\Message\ResponseInterface;
use RuntimeException;
Expand Down Expand Up @@ -38,14 +39,18 @@ private function __construct()
/**
* Maps a RequestException to the internal SchemaRegistryException types.
*
* @param RequestException $exception
* @param GuzzleException $exception
*
* @return SchemaRegistryException
*
* @throws RuntimeException
*/
public function __invoke(RequestException $exception): SchemaRegistryException
public function __invoke(GuzzleException $exception): SchemaRegistryException
{
if (!$exception instanceof RequestException) {
throw $exception;
}

$response = $this->guardAgainstMissingResponse($exception);
$decodedBody = $this->guardAgainstMissingErrorCode($response);
$errorCode = $decodedBody[self::ERROR_CODE_FIELD_NAME];
Expand Down
4 changes: 2 additions & 2 deletions src/Registry/PromisingRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use FlixTech\SchemaRegistryApi\Exception\ExceptionMap;
use FlixTech\SchemaRegistryApi\Schema\AvroReference;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Promise\PromiseInterface;
use InvalidArgumentException;
use Psr\Http\Message\RequestInterface;
Expand Down Expand Up @@ -45,7 +45,7 @@ public function __construct(ClientInterface $client)
$this->client = $client;
$exceptionMap = ExceptionMap::instance();

$this->rejectedCallback = static function (RequestException $exception) use ($exceptionMap) {
$this->rejectedCallback = static function (GuzzleException $exception) use ($exceptionMap) {
return $exceptionMap($exception);
};
}
Expand Down