Using the following method, you can disable the error handler for a specific module. In this example, I will name your module RESTful rest .
First create a new plugin in your application. For an example it will be Application_Plugin_RestErrorHandler . Add the following code to application/plugins/RestErrorHandler.php
class Application_Plugin_RestErrorHandler extends Zend_Controller_Plugin_Abstract { public function preDispatch(Zend_Controller_Request_Abstract $request) { $module = $request->getModuleName();
Then, in the Bootstrap module for the rest module, we register the plugin. This is located in modules/rest/Bootstrap.php . Since all modular bootstraps run independently of the current module, it can get into your main boot file, but I like to register plugins associated with a specific module in this modular bootstrap.
protected function _initPlugins() { $bootstrap = $this->getApplication(); $bootstrap->bootstrap('frontcontroller'); $front = $bootstrap->getResource('frontcontroller');
Another possibility is to save the error handler, but use a module-specific error handler. Thus, the error handler for your rest module can behave differently and produce a friendly REST error.
To do this, copy ErrorController.php to modules/rest/controllers/ErrorController.php and rename the class to Rest_ErrorController . Then copy the script view for the error controller to modules/rest/views/scripts/error/error.phtml .
Customize error.phtml to your liking so that the error message uses the same JSON / XML format used by your rest module.
Then we will make a little tweak for the plugin above. What we will do is tell Zend_Controller_Front to use ErrorController :: errorAction from the rest module instead of the default module. If you would like, you could use a different controller than ErrorController. Modify the plugin to look like this:
class Application_Plugin_RestErrorHandler extends Zend_Controller_Plugin_Abstract { public function preDispatch(Zend_Controller_Request_Abstract $request) { $module = $request->getModuleName(); if ($module != 'rest') return ; $errorHandler = Zend_Controller_Front::getInstance() ->getPlugin('Zend_Controller_Plugin_ErrorHandler');
Using the above method, you still need to register the plugin in Bootstrap.
Hope this helps.