[HttpClient] Throw JsonException instead of TransportException on empty response in Response::toArray()

This commit is contained in:
Jeroen Noten 2020-06-02 14:57:19 +02:00 committed by Jeroen Noten
parent a2f4342d08
commit 69547d9cfc
2 changed files with 7 additions and 1 deletions

View File

@ -137,7 +137,7 @@ trait ResponseTrait
public function toArray(bool $throw = true): array public function toArray(bool $throw = true): array
{ {
if ('' === $content = $this->getContent($throw)) { if ('' === $content = $this->getContent($throw)) {
throw new TransportException('Response body is empty.'); throw new JsonException('Response body is empty.');
} }
if (null !== $this->jsonData) { if (null !== $this->jsonData) {

View File

@ -35,6 +35,12 @@ class MockResponseTest extends TestCase
public function toArrayErrors() public function toArrayErrors()
{ {
yield [
'content' => '',
'responseHeaders' => [],
'message' => 'Response body is empty.',
];
yield [ yield [
'content' => '{}', 'content' => '{}',
'responseHeaders' => ['content-type' => 'plain/text'], 'responseHeaders' => ['content-type' => 'plain/text'],