SoapClient, catching exceptions as a response
Posted: Mon Feb 08, 2010 3:24 pm
Hi
I am looking for a solution with SoapClient. Basically, I have a script that connects to the remote soap server to check credentials email / passw combination. I am able to connect and if credentials are good, it returns the details for the user account. That part works. Now, if credentials fail, the WSDL at the soap server returns as a response two different exceptions: user not found and password is not valid. Somehow that triggers on my pert also SoapFault exception...
I want this to work this way, when email is not valid / does not exist, catch this exception from WSDL and display instead a friendly message on the login screen. And same, if password is not valid, catch WSDL soap server exception and return a nice message.
Unfortunately i don't have much experience with catching remote exceptions. I am wondering if there is a way to do it. I am trying to come up with a solution, something like you see below, only I don't know how to >>>
I want to have two exceptions, do I extend SoapFault, and how do i specify the condition for a specific custom exception to be thrown, when the remote server returns already an exception >>
Any suggestions???
Thanks
I am looking for a solution with SoapClient. Basically, I have a script that connects to the remote soap server to check credentials email / passw combination. I am able to connect and if credentials are good, it returns the details for the user account. That part works. Now, if credentials fail, the WSDL at the soap server returns as a response two different exceptions: user not found and password is not valid. Somehow that triggers on my pert also SoapFault exception...
I want this to work this way, when email is not valid / does not exist, catch this exception from WSDL and display instead a friendly message on the login screen. And same, if password is not valid, catch WSDL soap server exception and return a nice message.
Unfortunately i don't have much experience with catching remote exceptions. I am wondering if there is a way to do it. I am trying to come up with a solution, something like you see below, only I don't know how to >>>
Code: Select all
try
{
$client = new SoapClient("xxx.wsdl",array('trace' => 1));
}
catch (SoapFault $fault)
{
trigger_error("SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})", E_USER_ERROR);
}
if ($client)
{
try
{
$result = $client->call("login",array('email' => 'henry@domain.com','password' => 'xxxx'));
}
catch (InvalidCredentials $e)
{
echo "Ivalid Credentials";
}
catch (UknownUser $e)
{
echo "Unknown User";
}
}Code: Select all
Fatal error: Uncaught SoapFault exception: [soap:Client] Unknown Email in C:\project\soap.php:84 Stack trace: #0 [internal function]: SoapClient->__call('login', Array) #1 C:\project\soap.php(84): SoapClient->login(Array) #2 C:\project\soap.php(23) {main} thrown in C:\project\soap.php on line 84Thanks