Closed
Description
Symfony version(s) affected: 4.3.0 - 5.1.0
Description
When calling toArray()
on a response with an empty body, a TransportException
is thrown. A TransportException
should be thrown on network errors. However, responses with empty body might be completely valid. In that case, toArray()
should throw JsonException
(or other exception that implements DecodingExceptionInterface
) should be thrown, because the reponse body does not contain valid JSON.
How to reproduce
$httpClient = HttpClient::create();
$response = $httpClient->request('GET', 'https://httpbin.org/status/201');
$response->toArray(); // throws TransportException with message 'Response body is empty.'
Possible Solution
Throw a JsonException
instead of a TransportException
when response body is empty.