title: Catch Guzzle exceptions on connections refused
body: <p>I am using Guzzle with the following code:</p>
  <pre class="lang-php prettyprint-override"><code>try {
      $client = new Client();
      $result = $client-&gt;get(&quot;http://{$request-&gt;ES_HOST}:{$request-&gt;ES_PORT}&quot;, [
              'headers' =&gt; ['Content-Type' =&gt; 'application/json'],
              'auth' =&gt; [$request-&gt;ES_LOGIN, $request-&gt;ES_PASSWORD],
              'allow_redirects' =&gt; false,
          ]);
      $response['status'] = $result-&gt;getStatusCode();
      $response['message'] = json_decode($result-&gt;getBody()-&gt;getContents());
  } catch (RequestException $e) {
      $response['status'] = $e-&gt;getResponse()-&gt;getStatusCode();
      $response['message'] = $e-&gt;getMessage();
  }
  </code></pre>
  <p>And it works well however when an user gives the wrong URL for guzzle to process it instead of getting catched in <code>RequestException</code> it gives an 500 error in the server and returns a regular <code>Exception</code> with the message of <code>cURL error 7: Failed to connect to [host] port [port]: Connection refused</code>. Hoe can I make it so that I can catch the error and status code as well to return to the user?</p>