ZF-7670: Handling "Unknown Error" from unregistered soap exceptions
Description
When using the soap server in a large multifunctional application and an Exception occurs that is not found in registered Exception types It throw a rather unhelpful "Unknown Error".
I have had to edit the Fault method in Zend_Soap_Server. to allow the passing of non registered exceptions.
My patch is quick and dirty but it may be worth adding an option flag that can be set to allow the use of unregistered Exceptions.
method now reads as
public function fault($fault = null, $code = "Receiver")
{
if ($fault instanceof Exception) {
$class = get_class($fault);
if (in_array($class, $this->_faultExceptions)) {
$message = $fault->getMessage();
$eCode = $fault->getCode();
$code = empty($eCode) ? $code : $eCode;
} else {
$eCode = $fault->getCode();
$code = empty($eCode) ? $code : $eCode;
$message = 'Unregistered Exception: "'.$class.'" '.$fault->getMessage();
}
} elseif(is_string($fault)) {
$message = $fault;
} else {
$message = 'Unknown error';
}
$allowedFaultModes = array(
'VersionMismatch', 'MustUnderstand', 'DataEncodingUnknown',
'Sender', 'Receiver', 'Server'
);
if(!in_array($code, $allowedFaultModes)) {
$code = "Receiver";
}
return new SoapFault($code, $message);
}
Comments
Posted by Benjamin Eberlei (beberlei) on 2009-09-04T13:25:05.000+0000
Sounds like a maybe, i'll think about it
Posted by Amr Mostafa (alienbrain) on 2009-09-06T01:11:51.000+0000
Perhaps one simple way of doing that is to check using {{instanceof}} instead of {{get_class}}. That way, if someone wants to allow all exceptions, they can register the base exception class {{Exception}}.
Posted by Curtis Corliss (ccorliss) on 2010-02-28T04:28:19.000+0000
I agree with the concept of registering exceptions with the soap server, as opposed to directly returning all exceptions as seen in the description code. However - I don't think comparing the class name as a string is the best approach. This can make error handling very cumbersome in more complex applications.
I have attached a patch to check if the thrown exception is an instance of a registered exception.
Posted by Curtis Corliss (ccorliss) on 2010-02-28T04:48:20.000+0000
Can you review this patch? I don't have commit privileges yet.
Posted by Levi Stanley (niterain) on 2010-03-19T06:48:13.000+0000
Interesting, I was getting this error last month, ended up just using Zend's autodiscovery, and using php's soap server directly instead. Since it gave more useful information.