Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7400823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:18:28+00:00 2026-05-29T04:18:28+00:00

I have a module Api where I am trying to implement a RESTful API.

  • 0

I have a module Api where I am trying to implement a RESTful API. The problem is that when I throw an exception in that module, I would like the exception to be thrown and not handled by the error controller in the default module.

Is it possible to disable the error controller for just a specific module in Zend Framework?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:18:28+00:00Added an answer on May 29, 2026 at 4:18 am

    Using the following method you could disable the error handler for a specific module. In this example, I will call your RESTful module rest.

    First, create a new plugin in your application. For the example, this 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();
    
            // don't run this plugin unless we are in the rest module
            if ($module != 'rest') return ;
    
            // disable the error handler, this has to be done prior to dispatch()
            Zend_Controller_Front::getInstance()->setParam('noErrorHandler', true); 
        }
    }
    

    Next, in your module Bootstrap for the rest module, we will register the plugin. This is in modules/rest/Bootstrap.php. Since all module bootstraps are executed regardless of the current module, it could go in your main bootstrap, but I like to register plugins related to a specific module in that module’s bootstrap.

    protected function _initPlugins()
    {
        $bootstrap = $this->getApplication();
        $bootstrap->bootstrap('frontcontroller');
        $front = $bootstrap->getResource('frontcontroller');
    
        // register the plugin
        $front->registerPlugin(new Application_Plugin_RestErrorHandler());
    }
    

    Another possibility would be to keep the error handler, but use a module specific error handler. This way, the error handler for your rest module could behave differently and output a REST friendly error.

    To do that, copy ErrorController.php to modules/rest/controllers/ErrorController.php and rename the class to Rest_ErrorController. Next, copy the view script for the error controller to modules/rest/views/scripts/error/error.phtml.

    Customize error.phtml to your liking so the error message uses the same JSON/XML format used by your rest module.

    Then, we will make a slight tweak to 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 wanted, you could even use a different controller than ErrorController. Change the plugin to look like the following:

    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');
    
            // change the error handler being used from the one in the default module, to the one in the rest module
            $errorHandler->setErrorHandlerModule($module); 
        }
    }
    

    With the above method, you still need to register the plugin in Bootstrap.

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have a RESTful api module which has several resources. I am trying
How would I dynamically add methods to my module through the C-API? I have
I have a Drupal module that talks to a REST API on a separate
I have module application. When I run it, the main window of that app
I have module that implements custom content type via NodeAPI hooks ( hook_insert ,
I have a module in the parent directory of my script and I would
I have a module that sends an email to a specified email address but
I have a module that reads the StandardError of a process. Everything works fine,
Let's say that I have a module that has a Queue in it. For
I'm trying to build a python library for interacting with our RESTful API, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.