codeinchaos/restful-zend-framework — pull request #6 by ishenkoyv (2012-02-18 18:53:35+00:00)
Title: Added REST_Exception class to work with rest errors through exceptions

Added REST_Exception class to work with rest errors through exceptions
Exception class can be extended in future to get error code on input and return localized response

Example of usage

public function getAction()
{
$result = array();
$user = null;
$id = $this->_getParam('id');

if (is_numeric($id)) {
$user = $this->getEntityManager()->getRepository(Users_Model_User')->findOneById($id);
} else {
$user = $this->getEntityManager()->getRepository('Users_Model_User')->findOneByName((string) $id);
}

if (!$user) {
throw new REST_Exception('No such user');
}
....

$this->checkDomainOwner($domain, $user);

$this->view->result = array('domain' => $domain->getDataForApi());
$this->_response->ok();
}