I've trying to find a way of catching SOAP exceptions in a CodeIgniter model, I searched for hours and all I found was more people trying to get an answer without success.
How can I catch exceptions when creating a new instance of SoapClient? I tried the following way but codeIgniter still gives me "A PHP Error was encountered" page, which in this project is fine in most of cases.
class User_model extends CI_Model
{
public function __construct()
{
$this->WAPI_service_url = 'http://api.lan/WAPITranslator/WAPITranslator.asmx?wsdl';
try{
$this->connection = new SoapClient($this->WAPI_service_url, array('trace' => 1, "exception" => 0));
}
catch(Exception $e){
return false;
}
}
Following the PHP docs, i would do it like this:
class User_model extends CI_Model
{
public function __construct() {
$this->WAPI_service_url = 'http://api.lan/WAPITranslator/WAPITranslator.asmx?wsdl';
try {
$this->connection = new SoapClient($this->WAPI_service_url, array('trace' => 1, "exceptions" => true));
} catch (Exception $e){
$e->getMessage(); // get the error message and save it somewhere
$e->getCode(); // gets the error code
}
}
}