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

Commitf84c83b

Browse files
committed
[HttpClient] Check satus code before decoding in TraceableResponse::toArray()
1 parenta29af81 commitf84c83b

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ public function getContent(bool $throw = true): string
6363

6464
publicfunctiontoArray(bool$throw =true):array
6565
{
66-
$this->content =$this->response->toArray(false);
67-
6866
if ($throw) {
6967
$this->checkStatusCode($this->response->getStatusCode());
7068
}
7169

70+
$this->content =$this->response->toArray(false);
71+
7272
return$this->content;
7373
}
7474

‎src/Symfony/Component/HttpClient/Tests/TraceableHttpClientTest.php‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
useSymfony\Component\HttpClient\NativeHttpClient;
1717
useSymfony\Component\HttpClient\Response\MockResponse;
1818
useSymfony\Component\HttpClient\TraceableHttpClient;
19+
useSymfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
1920
useSymfony\Contracts\HttpClient\HttpClientInterface;
2021
useSymfony\Contracts\HttpClient\Test\TestHttpServer;
2122

@@ -100,4 +101,16 @@ public function testStream()
100101
$this->assertGreaterThan(1,\count($chunks));
101102
$this->assertSame('Symfony is awesome!',implode('',$chunks));
102103
}
104+
105+
publicfunctiontestToArrayChecksStatusCodeBeforeDecoding()
106+
{
107+
$this->expectException(ClientExceptionInterface::class);
108+
109+
$sut =newTraceableHttpClient(newMockHttpClient($responseFactory =function ():MockResponse {
110+
returnnewMockResponse('Errored.', ['http_code' =>400]);
111+
}));
112+
113+
$response =$sut->request('GET','https://example.com/foo/bar');
114+
$response->toArray();
115+
}
103116
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp