Home » Php » php – Soap runtime error not catching exception

php – Soap runtime error not catching exception

Posted by: admin August 13, 2018 Leave a comment

Questions:

I’m using PHP-NTML, for calling soap service, passing following option to wsdl

$this->soap = new SoapClient($wsdl, [
  'user' => $userName,
  'password' => $password,
  'trace' => 1,
  'cache_wsdl' => WSDL_CACHE_NONE,
  'exception' => 1,
]);

Calling code is as follows

 try {
  $response = $this->soap->__soapCall('Method1', [
    $param,
  ]);
}
catch (\SoapFault $f) {
  $resp = new RedirectResponse(\Drupal::url('mymodule.login_error'));
  $resp->send();
}
catch (\RuntimeException $e) {
  $resp = new RedirectResponse(\Drupal::url('mymodule.login_error'));
  $resp->send();
}

Service calling code is works perfectly fine, now I’m trying to handle exceptions, but during execution RuntimeException is occurring but it is not hitting catch RuntimeException code instead it show WSOD (white page) with error message.

Answers: