title: How to catch 500 error in Controller using Laravel
body: <p>I need to connect to an API so I write a function:</p>
  
  <pre><code>try {
      $res4 = $client3-&gt;post('https://api.example.co.uk/Book', [
          'headers' =&gt; [
              'Accept' =&gt; 'application/json',
              'Content-Type' =&gt; 'application/json',
              'Authorization' =&gt; 'Bearer ajhsdbjhasdbasdbasd',
          ],
          'json' =&gt; [
              'custFirstName' =&gt; $FirstName,
              'custLastName' =&gt; $Surname,
              'custPhone' =&gt; $Mobile,
              'custEmail' =&gt; $Email,
          ]
      ]);
  } catch (GuzzleHttp\Exception\ClientException $e) {
      $response = $e-&gt;getResponse();
      $result = json_decode($response-&gt;getBody()-&gt;getContents());
      $item-&gt;update(['status' =&gt; 'Problems at step3']);
      Mail::raw('Problem at STEP 3', function ($message) use ($serial) {
          $message-&gt;from('asd.asd@gmail.com', 'asd.asd@gmail.com');
          $message-&gt;subject('We got a problem etc.');
          $message-&gt;to('john.smith@gmail.com');
      });
  }
  </code></pre>
  
  <p>As you can see I need to make a call to API but in the case when API is down I write catch functions.</p>
  
  <p>But now when API is down and API return '500 Internal Error' this function is just crashed ... </p>
  
  <p>My question is why catch dont handle it? </p>
  
  <p>How I can handle errors - when API is down or bad request... WHy catch{} doesn't work?</p>
  
  <p>UPDATE: here is my laravel.log</p>
  
  <pre><code>[2018-10-25 14:51:04] local.ERROR: GuzzleHttp\Exception\ServerException: Server error: `POST https://api.example.co.uk/Book` resulted in a `500 Internal Server Error` response:
  {"message":"An error has occured. Please contact support."}
   in /home/public_html/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:107
  Stack trace:
  #0 /home/public_html/vendor/guzzlehttp/guzzle/src/Middleware.php(65): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response))
  #1 /home/public_html/vendor/guzzlehttp/promises/src/Promise.php(203): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response))
  </code></pre>