How can I pass script execution errors to the XMLRPC response so I don't get a Fault Exception?
Maybe I'm not setting this up right:
In the XMLRPC server I'm adding Zend_XmlRpc_Server_Fault::attachFaultException('Exception');
like this:
Zend_XmlRpc_Server_Fault:开发者_如何学运维:attachFaultException('Exception');
$server = new Zend_XmlRpc_Server();
But I still get a Fault Exception:
Fault Exception:\n651Failed to parse response
How can I pass the script execution errors to the response?
I've also tried to set this with no luck:
error_reporting(E_ALL);
ini_set("display_errors",1);
ini_set("xmlrpc_errors",1);
Docs: http://php.net/manual/en/errorfunc.configuration.php
Example XMLRPC error when script has errors:
Fault Exception:\n651Failed to parse response
Example of when script has errors:
Fatal error: Call to undefined method
Both are from the same script error, but I need the XMLRPC to display the Fatal error message in the response instead of giving the failed to parse response.
You can use the set_error_handler() function to intercept a script error and instead throw an ErrorException:
function exception_error_handler($errno, $errstr, $errfile, $errline ) {
throw new ErrorException($errstr, $errno, 0, $errfile, $errline);
}
So when you call Zend_XmlRpc_Server::handle():
set_error_handler('exception_error_handler');
$server->handle();
restore_error_handler();
Edit: Example #1 from the ErrorException page is wrong. Use the version in this answer instead.
精彩评论