Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...

When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Handling errors

In addition to the standard suite of exceptions thrown by Zend_Gdata, requests using the Provisioning API may also throw a Zend_Gdata_Gapps_ServiceException. These exceptions indicate that a API specific error occurred which prevents the request from completing.

Each ServiceException instance may hold one or more Error objects. Each of these objects contains an error code, reason, and (optionally) the input which triggered the exception. A complete list of known error codes is provided in Zend Framework's API documentation under Zend_Gdata_Gapps_Error. Additionally, the authoritative error list is available online at Google Apps Provisioning API V2.0 Reference: Appendix D.

While the complete list of errors received is available within ServiceException as an array by calling getErrors(), often it is convenient to know if one specific error occurred. For these cases the presence of an error can be determined by calling hasError().

The following example demonstrates how to detect if a requested resource doesn't exist and handle the fault gracefully:

function retrieveUser ($username) {
$query $gdata->newUserQuery($username);
    try {
$user $gdata->getUserEntry($query);
    } catch (
Zend_Gdata_Gapps_ServiceException $e) {
// Set the user to null if not found
if ($e->hasError(Zend_Gdata_Gapps_Error::ENTITY_DOES_NOT_EXIST)) {
$user null;
        } else {

Zend Framework