Skip to content

Commit 3aedb51

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

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

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

Lines 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

Lines 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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy