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

Appearance settings

Commit 3aedb51

Browse filesBrowse files
jderussenicolas-grekas
authored andcommitted
[HttpClient] Fix exception triggered with AsyncResponse
1 parent d0ded92 commit 3aedb51
Copy full SHA for 3aedb51

File tree

2 files changed

+21
-5
lines changed
Filter options

2 files changed

+21
-5
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Response/AsyncResponse.php
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,11 @@ public static function stream(iterable $responses, float $timeout = null, string
206206
foreach ($client->stream($wrappedResponses, $timeout) as $response => $chunk) {
207207
$r = $asyncMap[$response];
208208

209+
if (null === $chunk->getError() && $chunk->isFirst()) {
210+
// Ensure no exception is thrown on destruct for the wrapped response
211+
$r->response->getStatusCode();
212+
}
213+
209214
if (!$r->passthru) {
210215
if (null !== $chunk->getError() || $chunk->isLast()) {
211216
unset($asyncMap[$response]);
@@ -219,11 +224,6 @@ public static function stream(iterable $responses, float $timeout = null, string
219224
continue;
220225
}
221226

222-
if (null === $chunk->getError() && $chunk->isFirst()) {
223-
// Ensure no exception is thrown on destruct for the wrapped response
224-
$r->response->getStatusCode();
225-
}
226-
227227
foreach (self::passthru($r->client, $r, $chunk, $asyncMap) as $chunk) {
228228
yield $r => $chunk;
229229
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Tests/AsyncDecoratorTraitTest.php
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,22 @@ public function testRetry404()
6262
$this->assertSame(200, $response->getStatusCode());
6363
}
6464

65+
public function testRetry404WithThrow()
66+
{
67+
$client = $this->getHttpClient(__FUNCTION__, function (ChunkInterface $chunk, AsyncContext $context) {
68+
$this->assertTrue($chunk->isFirst());
69+
$this->assertSame(404, $context->getStatusCode());
70+
$context->getResponse()->cancel();
71+
$context->replaceRequest('GET', 'http://localhost:8057/404');
72+
$context->passthru();
73+
});
74+
75+
$response = $client->request('GET', 'http://localhost:8057/404');
76+
77+
$this->expectException(ClientExceptionInterface::class);
78+
$response->getContent(true);
79+
}
80+
6581
public function testRetryTransportError()
6682
{
6783
$client = $this->getHttpClient(__FUNCTION__, function (ChunkInterface $chunk, AsyncContext $context) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.