[HttpClient] Fix exception triggered with AsyncResponse
This commit is contained in:
parent
d0ded920e6
commit
3aedb51dd8
@ -206,6 +206,11 @@ final class AsyncResponse implements ResponseInterface, StreamableInterface
|
||||
foreach ($client->stream($wrappedResponses, $timeout) as $response => $chunk) {
|
||||
$r = $asyncMap[$response];
|
||||
|
||||
if (null === $chunk->getError() && $chunk->isFirst()) {
|
||||
// Ensure no exception is thrown on destruct for the wrapped response
|
||||
$r->response->getStatusCode();
|
||||
}
|
||||
|
||||
if (!$r->passthru) {
|
||||
if (null !== $chunk->getError() || $chunk->isLast()) {
|
||||
unset($asyncMap[$response]);
|
||||
@ -219,11 +224,6 @@ final class AsyncResponse implements ResponseInterface, StreamableInterface
|
||||
continue;
|
||||
}
|
||||
|
||||
if (null === $chunk->getError() && $chunk->isFirst()) {
|
||||
// Ensure no exception is thrown on destruct for the wrapped response
|
||||
$r->response->getStatusCode();
|
||||
}
|
||||
|
||||
foreach (self::passthru($r->client, $r, $chunk, $asyncMap) as $chunk) {
|
||||
yield $r => $chunk;
|
||||
}
|
||||
|
@ -62,6 +62,22 @@ class AsyncDecoratorTraitTest extends NativeHttpClientTest
|
||||
$this->assertSame(200, $response->getStatusCode());
|
||||
}
|
||||
|
||||
public function testRetry404WithThrow()
|
||||
{
|
||||
$client = $this->getHttpClient(__FUNCTION__, function (ChunkInterface $chunk, AsyncContext $context) {
|
||||
$this->assertTrue($chunk->isFirst());
|
||||
$this->assertSame(404, $context->getStatusCode());
|
||||
$context->getResponse()->cancel();
|
||||
$context->replaceRequest('GET', 'http://localhost:8057/404');
|
||||
$context->passthru();
|
||||
});
|
||||
|
||||
$response = $client->request('GET', 'http://localhost:8057/404');
|
||||
|
||||
$this->expectException(ClientExceptionInterface::class);
|
||||
$response->getContent(true);
|
||||
}
|
||||
|
||||
public function testRetryTransportError()
|
||||
{
|
||||
$client = $this->getHttpClient(__FUNCTION__, function (ChunkInterface $chunk, AsyncContext $context) {
|
||||
|
Reference in New Issue
Block a user