Two kinds of errors can occur during an XML-RPC method call:
HTTP errors and XML-RPC faults. The
Zend_XmlRpc_Client recognizes each and provides the ability
to detect and trap them independently.
If any HTTP error occurs, such as the remote
HTTP server returns a 404 Not Found, a
Zend_XmlRpc_Client_HttpException will be thrown.
Example 1042. Handling HTTP Errors
<?php
$client = new Zend_XmlRpc_Client('http://foo/404');
try {
$client->call('bar', array($arg1, $arg2));
} catch (Zend_XmlRpc_Client_HttpException $e) {
// $e->getCode() returns 404
// $e->getMessage() returns "Not Found"
}
Regardless of how the XML-RPC client is used, the
Zend_XmlRpc_Client_HttpException will be thrown
whenever an HTTP error occurs.
An XML-RPC fault is analogous to a PHP
exception. It is a special type returned from an XML-RPC method
call that has both an error code and an error message. XML-RPC
faults are handled differently depending on the context of how the
Zend_XmlRpc_Client is used.
When the call() method or the server
proxy object is used, an XML-RPC fault will result in a
Zend_XmlRpc_Client_FaultException being thrown.
The code and message of the exception will map directly to
their respective values in the original XML-RPC fault
response.
Example 1043. Handling XML-RPC Faults
<?php
$client = new Zend_XmlRpc_Client('http://framework.zend.com/xmlrpc');
try {
$client->call('badMethod');
} catch (Zend_XmlRpc_Client_FaultException $e) {
// $e->getCode() returns 1
// $e->getMessage() returns "Unknown method"
}
When the call() method is used to make the
request, the Zend_XmlRpc_Client_FaultException will be
thrown on fault. A Zend_XmlRpc_Response object
containing the fault will also be available by calling
getLastResponse().
When the doRequest() method is used to make the
request, it will not throw the exception. Instead, it will
return a Zend_XmlRpc_Response object returned
will containing the fault. This can be checked with
isFault() instance method of
Zend_XmlRpc_Response.




