[HttpClient] fix throwing HTTP exceptions when the 1st chunk is emitted
This commit is contained in:
parent
9d882e8ce2
commit
3c93764f10
@ -317,20 +317,28 @@ trait ResponseTrait
|
||||
} elseif ($chunk instanceof ErrorChunk) {
|
||||
unset($responses[$j]);
|
||||
$isTimeout = true;
|
||||
} elseif ($chunk instanceof FirstChunk && $response->logger) {
|
||||
} elseif ($chunk instanceof FirstChunk) {
|
||||
if ($response->logger) {
|
||||
$info = $response->getInfo();
|
||||
$response->logger->info(sprintf('Response: "%s %s"', $info['http_code'], $info['url']));
|
||||
}
|
||||
|
||||
yield $response => $chunk;
|
||||
|
||||
if ($response->initializer && null === $response->info['error']) {
|
||||
// Ensure the HTTP status code is always checked
|
||||
$response->getHeaders(true);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
yield $response => $chunk;
|
||||
}
|
||||
|
||||
unset($multi->handlesActivity[$j]);
|
||||
|
||||
if ($chunk instanceof FirstChunk && null === $response->initializer && null === $response->info['error']) {
|
||||
// Ensure the HTTP status code is always checked
|
||||
$response->getHeaders(true);
|
||||
} elseif ($chunk instanceof ErrorChunk && !$chunk->didThrow()) {
|
||||
if ($chunk instanceof ErrorChunk && !$chunk->didThrow()) {
|
||||
// Ensure transport exceptions are always thrown
|
||||
$chunk->getContent();
|
||||
}
|
||||
|
@ -152,6 +152,16 @@ abstract class HttpClientTestCase extends TestCase
|
||||
$this->assertSame(404, $response->getStatusCode());
|
||||
$this->assertSame(['application/json'], $response->getHeaders(false)['content-type']);
|
||||
$this->assertNotEmpty($response->getContent(false));
|
||||
|
||||
$response = $client->request('GET', 'http://localhost:8057/404');
|
||||
|
||||
try {
|
||||
foreach ($client->stream($response) as $chunk) {
|
||||
$this->assertTrue($chunk->isFirst());
|
||||
}
|
||||
$this->fail(ClientExceptionInterface::class.' expected');
|
||||
} catch (ClientExceptionInterface $e) {
|
||||
}
|
||||
}
|
||||
|
||||
public function testIgnoreErrors()
|
||||
|
Reference in New Issue
Block a user