Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[HttpClient] Response::toArray() throws TransportException instead of JsonException when response body is empty #37064

Copy link
Copy link
Closed
@jeroennoten

Description

@jeroennoten
Issue body actions

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.