Skip to content

Commit 98b17a1

Browse files
authored
Merge pull request #2 from hotalo/bugfix/fix-exception-handle
异常处理修复
2 parents 4888a91 + d837ace commit 98b17a1

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

‎src/JsonRpcClient/JsonRpcClient.php‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
use Datto\JsonRpc\Responses\ErrorResponse;
66
use Datto\JsonRpc\Responses\ResultResponse;
77
use GuzzleHttp\Client;
8-
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
9-
use Symfony\Contracts\HttpClient\Exception\ExceptionInterface;
10-
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
8+
use GuzzleHttp\Exception\ClientException;
9+
use GuzzleHttp\Exception\GuzzleException;
10+
use GuzzleHttp\Exception\RequestException;
1111

1212
class JsonRpcClient
1313
{
@@ -82,16 +82,16 @@ public function call()
8282
'body' => $protocol->encode(),
8383
]);
8484
$content = $response->getBody();
85-
} catch (ExceptionInterface $e) {
85+
} catch (GuzzleException $e) {
8686
$detail = null;
87-
if ($e instanceof ServerExceptionInterface || $e instanceof ClientExceptionInterface) {
87+
if ($e instanceof ClientException || ($e instanceof RequestException && $e->hasResponse())) {
8888
$response = $e->getResponse();
8989
$detail = [
9090
'http_code' => $response->getStatusCode(),
91-
'content' => $response->getContent(false),
92-
'info' => $response->getInfo(),
91+
'content' => (string) $response->getBody()
9392
];
9493
}
94+
9595
throw new JsonRpcException($e->getMessage(), $e->getCode(), $detail);
9696
}
9797

0 commit comments

Comments
 (0)