Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit897b21d

Browse files
committed
[HttpClient] Throw JsonException instead of TransportException on empty response in Response::toArray()
1 parent4368848 commit897b21d

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

‎src/Symfony/Component/HttpClient/Response/ResponseTrait.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function getContent(bool $throw = true): string
132132
publicfunctiontoArray(bool$throw =true):array
133133
{
134134
if ('' ===$content =$this->getContent($throw)) {
135-
thrownewTransportException('Response body is empty.');
135+
thrownewJsonException('Response body is empty.');
136136
}
137137

138138
if (null !==$this->jsonData) {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespaceSymfony\Component\HttpClient\Tests\Response\Response;
4+
5+
usePHPUnit\Framework\TestCase;
6+
useSymfony\Component\HttpClient\Exception\JsonException;
7+
useSymfony\Component\HttpClient\Response\MockResponse;
8+
9+
/**
10+
* Test methods from Symfony\Component\HttpClient\Response\ResponseTrait.
11+
*/
12+
class MockResponseTestextends TestCase
13+
{
14+
/**
15+
* @dataProvider toArrayErrors
16+
*/
17+
publicfunctiontestToArrayError($content,$responseHeaders,$message)
18+
{
19+
$this->expectException(JsonException::class);
20+
$this->expectExceptionMessage($message);
21+
22+
$response =newMockResponse($content, ['response_headers' =>$responseHeaders]);
23+
$response = MockResponse::fromRequest('GET','https://example.com/file.json', [],$response);
24+
$response->toArray();
25+
}
26+
27+
publicfunctiontoArrayErrors()
28+
{
29+
yield [
30+
'content' =>'',
31+
'responseHeaders' => [],
32+
'message' =>'Response body is empty.',
33+
];
34+
}
35+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp