PhpRiot
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

When using Nirvanix, it's important to anticipate errors that can be returned by the service and handle them appropriately.

All operations against the REST service result in an XML return payload that contains a ResponseCode element, such as the following example:

<Response>
   <ResponseCode>0</ResponseCode>
</Response>

When the ResponseCode is zero such as in the example above, the operation was successful. When the operation is not successful, the ResponseCode is non-zero and an ErrorMessage element should be present.

To alleviate the need to repeatedly check if the ResponseCode is non-zero, Zend_Service_Nirvanix automatically checks each response returned by Nirvanix. If the ResponseCode indicates an error, a Zend_Service_Nirvanix_Exception will be thrown.

$auth = array('username' => 'your-username',
              'password' => 'your-password',
              'appKey'   => 'your-app-key');
$nirvanix = new Zend_Service_Nirvanix($auth);

try {

  $imfs = $nirvanix->getService('IMFS');
  $imfs->unlink('/a-nonexistant-path');

} catch (Zend_Service_Nirvanix_Exception $e) {
  echo $e->getMessage() . "\n";
  echo $e->getCode();
}

In the example above, unlink() is a convenience method that wraps the DeleteFiles command on the REST API. The filePath parameter required by the DeleteFiles command contains a path that does not exist. This will result in a Zend_Service_Nirvanix exception being thrown with the message "Invalid path" and code 70005.

The Nirvanix API Documentation describes the errors associated with each command. Depending on your needs, you may wrap each command in a try block or wrap many commands in the same try block for convenience.

Zend Framework