I am using guzzle to call web service .If there is any error i get white screen with error. 'GuzzleHttp\Exception\ClientException: Client error'

My code is as follow: try { $response = $this->httpClient->post($endPoint, [ 'verify' => FALSE, 'body' => Json::encode($data), 'headers' => [ 'Auth-Token' => $token, 'Content-Type' => 'application/json', ], ]) } catch (RequestException $e) { watchdog_exception('message', $e->getMessage()); }

if i add 'http_errors' => false as option in post request i don't get white screen. Is there any other way of implementation that i don't get white screen with error if try block fails. The desired feature is if there is a error in calling web service the default page should reload.

  • @mradcliffe The solution on stackoverflow.com/a/30957410/5334703 is not working – Aditya Joshi Jun 14 '17 at 17:00
  • Your comment doesn't really help. You may not be implementing guzzle or exception handling correctly in your code per guzzle documentation. – mradcliffe Jun 15 '17 at 17:51
  • 1
    It finally work! i was missing name space "use GuzzleHttp\Exception\RequestException;" – Aditya Joshi Jun 16 '17 at 20:53

Browse other questions tagged or ask your own question.