ricardofiorani/guzzle-psr18-adapter

GuzzleHttp\Exception\BadResponseException requires a Response object

Closed this issue · 2 comments

While I was preparing my package for PSR-18 and used your Guzzle adapter for it, I hit the following error message: Instantiating the GuzzleHttp\Exception\BadResponseException class without a Response is deprecated since version 6.3 and will be removed in 7.0.

The stack trace:

 vendor/guzzlehttp/guzzle/src/Exception/BadResponseException.php:22
 vendor/ricardofiorani/guzzle-psr18-adapter/src/Client.php:42

The fix is fairly easy: Just adding a GuzzleHttp\Psr7\Response instantiation when an exception is raised.

    public function sendRequest(RequestInterface $request): ResponseInterface
    {
        try {
            return $this->send($request);
        } catch (GuzzleException $e) {
            $response = new Response();
            throw new ClientException($e->getMessage(), $request, $response, $e);
        }
    }

Maybe you want to instantiate the Response object outside this client extension, but for now it's a quick win.

Hi DragonBe, thank you for this and sorry for the lack of input.
It was fixed in v1.0.3

This issue is not fixed with 438353d.
Instead of catching the BadResponseException, the creation of the ClientException (which extends the BadResponse Exception) is the problem. In line 42 the ClientException is instantiated with null as response param which is deprecated.