You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
jeroennoten
changed the title
[Http-Client] Response::toArray() throws TransportException instead of JsonException when response body is empty
[HttpClient] Response::toArray() throws TransportException instead of JsonException when response body is empty
Jun 2, 2020
…tion on empty response in Response::toArray() (jeroennoten)
This PR was merged into the 4.4 branch.
Discussion
----------
[HttpClient] Throw JsonException instead of TransportException on empty response in Response::toArray()
| Q | A
| ------------- | ---
| Branch? | 4.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | Fix#37064
| License | MIT
Commits
-------
69547d9 [HttpClient] Throw JsonException instead of TransportException on empty response in Response::toArray()
Symfony version(s) affected: 4.3.0 - 5.1.0
Description
When calling
toArray()
on a response with an empty body, aTransportException
is thrown. ATransportException
should be thrown on network errors. However, responses with empty body might be completely valid. In that case,toArray()
should throwJsonException
(or other exception that implementsDecodingExceptionInterface
) should be thrown, because the reponse body does not contain valid JSON.How to reproduce
Possible Solution
Throw a
JsonException
instead of aTransportException
when response body is empty.The text was updated successfully, but these errors were encountered: