Skip to content

Commit b96e914

Browse files
committed
[HttpClient] Throw JsonException instead of TransportException on empty response in Response::toArray()
1 parent d850d6e commit b96e914

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Response/ResponseTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function getContent(bool $throw = true): string
137137
public function toArray(bool $throw = true): array
138138
{
139139
if ('' === $content = $this->getContent($throw)) {
140-
throw new TransportException('Response body is empty.');
140+
throw new JsonException('Response body is empty.');
141141
}
142142

143143
if (null !== $this->jsonData) {

Tests/Response/MockResponseTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ public function testToArrayError($content, $responseHeaders, $message)
3535

3636
public function toArrayErrors()
3737
{
38+
yield [
39+
'content' => '',
40+
'responseHeaders' => [],
41+
'message' => 'Response body is empty.',
42+
];
43+
3844
yield [
3945
'content' => '{}',
4046
'responseHeaders' => ['content-type' => 'plain/text'],

0 commit comments

Comments
 (0)