Skip to content

[Http-Client] Http-Client with Psr18Client, implementation doesn't provide the right exception #31979

@kevin-lot

Description

@kevin-lot

Symfony version(s) affected: 4.3

Description

http-client with Psr18Client implementation doesn't provide the right exception (when 400 or above code is returned for example).

"Psr\Http\Client\ClientExceptionInterface" is expected instead of "Symfony\Component\HttpClient\Exception\ClientExceptionInterface".

How to reproduce

Do a "sendRequest" with "Psr18Client" that returns 404.

Possible Solution

In Psr18Client::sendRequest, catch the Symfony exception to re-throw it in Psr exception ?

Additional context

The default Psr18Client constructor create a symfony HttpClient then the response is "CurlReponse" or "NativeResponse" with "ResponseTrait" inside.

The method "Symfony\Component\HttpClient\Response\ResponseTrait::checkStatusCode()" throws "Symfony\Component\HttpClient\Exception\ClientException".
This exception appends when "$response->getHeaders()" in "Psr18Client::sendRequest" is called (without disabling throw), a check is done in "Symfony\Component\HttpClient\Response\ResponseTrait::checkStatusCode()".

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