'Guzzle HTTP 500 error instead of error message

I'm trying to call an API with Guzzle, but if a non-200 response comes back, I get an HTTP 500 error.

Client error response [url] https://myapi.test.com [status code] 400 [reason phrase] Bad Request

If I call the URL from Postman with the same body, then I get back the error message as to why the request is bad.

        try {
            $response = $this->client->post(
                'myapi.test.com',
                array(
                    'headers' => $this->getHeaders(),
                    'body' => $json
                )
            );
        } catch (GuzzleHttp\Exception\ClientException $e) {
            $response = $e->getResponse();
            var_dump($response);die();
        }

But it doesn't reach the exception section.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source