Re: [fw-general] issues with Zend_Controller_Plugin_ErrorHandler
Hey Dan, That's really not how you're supposed to do it. You should rather set your own errorcode in the constructor when throwing the exception. In my application (namely within a given controller) I throw an exception like this: // [...] throw new Zend_Controller_Exception(Oops! You're not supposed to be here., 100); Then, in the ErrorController I simply retrieve my errorcode and do whatever I want with it. You will note that $errors-exception-code is protected and hence not accessible. That's where the Exception::getCode() method comes in handy: $errors = $this-_getParam('error_handler'); switch ($errors-exception-getCode()) { case 100: echo Access denied.; break; default: } Alternatively you could work with your own constants too. Hope that helps. Cheers Bastian On Aug 16, 2007, at 10:17 PM, Dan Rossi wrote: Thanks matt, ill do the forwards in the caught exception, im not sure if Zend_Auth throw exceptions though. Matthew Weier O'Phinney wrote: -- Dan Rossi [EMAIL PROTECTED] wrote (on Thursday, 16 August 2007, 07:33 PM +1000): Hi trying to bubble an error when throwing something like this as Zend_Auth wont do it for u it seems if (!$auth-hasIdentity()) { throw new Zend_Auth_Adapter_Exception(Not Allowed Access); } The return type to the error controller is always EXCEPTION_OTHER. Id like it to be a EXCEPTION_AUTH_FAILED code or whatever so that i am able to display some custom template for a particular code / type. switch ($exceptionType) { case 'Zend_Controller_Dispatcher_Exception': $error-type = self::EXCEPTION_NO_CONTROLLER; break; case 'Zend_Controller_Action_Exception': $error-type = self::EXCEPTION_NO_ACTION; break; default: $error-type = self::EXCEPTION_OTHER; break; } Bastian Gerhard Product Manager __ Ashley Associates Ltd. Technology Group Minami-Aoyama First Building 8F 7-8-1 Minami-Aoyama Minato-ku, Tokyo 107-0062
[fw-general] issues with Zend_Controller_Plugin_ErrorHandler
Hi trying to bubble an error when throwing something like this as Zend_Auth wont do it for u it seems if (!$auth-hasIdentity()) { throw new Zend_Auth_Adapter_Exception(Not Allowed Access); } The return type to the error controller is always EXCEPTION_OTHER. Id like it to be a EXCEPTION_AUTH_FAILED code or whatever so that i am able to display some custom template for a particular code / type. switch ($exceptionType) { case 'Zend_Controller_Dispatcher_Exception': $error-type = self::EXCEPTION_NO_CONTROLLER; break; case 'Zend_Controller_Action_Exception': $error-type = self::EXCEPTION_NO_ACTION; break; default: $error-type = self::EXCEPTION_OTHER; break; } Let me know.
Re: [fw-general] issues with Zend_Controller_Plugin_ErrorHandler
-- Dan Rossi [EMAIL PROTECTED] wrote (on Thursday, 16 August 2007, 07:33 PM +1000): Hi trying to bubble an error when throwing something like this as Zend_Auth wont do it for u it seems if (!$auth-hasIdentity()) { throw new Zend_Auth_Adapter_Exception(Not Allowed Access); } The return type to the error controller is always EXCEPTION_OTHER. Id like it to be a EXCEPTION_AUTH_FAILED code or whatever so that i am able to display some custom template for a particular code / type. switch ($exceptionType) { case 'Zend_Controller_Dispatcher_Exception': $error-type = self::EXCEPTION_NO_CONTROLLER; break; case 'Zend_Controller_Action_Exception': $error-type = self::EXCEPTION_NO_ACTION; break; default: $error-type = self::EXCEPTION_OTHER; break; } In the default case, you'd then need to look at the exception itself. Try this: switch ($error-type) { case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER: case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION: // these are basically 404s... display some message to that // effect... break; default: $eClass = get_class($error-exception); switch ($eClass) { case 'Zend_Auth_Adapter_Exception': // authentication error... break; case ... } } However, probably a better method would be to do a try/catch around the call throwing the exception, and forwarding to a custom error from there: try { $identity = $auth-getIdentity(); } catch (Zend_Auth_Adapter_Exception $e) { return $this-_forward('auth', 'error', 'default'); } The ErrorHandler plugin is primarily for routing dispatch exceptions (i.e., controller or action not found) and unhandled application exceptions. You should try and handle exceptions in your applications as much as possible, particularly if you will be wanting to do custom error reporting for them. Don't go overboard, though -- database errors are typically an edge case when catching exceptions, so allowing those to bubble up to the ErrorHandler plugin makes sense. However, Your auth example is a prime candidate for targetted error handling within the application. -- Matthew Weier O'Phinney PHP Developer| [EMAIL PROTECTED] Zend - The PHP Company | http://www.zend.com/
Re: [fw-general] issues with Zend_Controller_Plugin_ErrorHandler
Thanks matt, ill do the forwards in the caught exception, im not sure if Zend_Auth throw exceptions though. Matthew Weier O'Phinney wrote: -- Dan Rossi [EMAIL PROTECTED] wrote (on Thursday, 16 August 2007, 07:33 PM +1000): Hi trying to bubble an error when throwing something like this as Zend_Auth wont do it for u it seems if (!$auth-hasIdentity()) { throw new Zend_Auth_Adapter_Exception(Not Allowed Access); } The return type to the error controller is always EXCEPTION_OTHER. Id like it to be a EXCEPTION_AUTH_FAILED code or whatever so that i am able to display some custom template for a particular code / type. switch ($exceptionType) { case 'Zend_Controller_Dispatcher_Exception': $error-type = self::EXCEPTION_NO_CONTROLLER; break; case 'Zend_Controller_Action_Exception': $error-type = self::EXCEPTION_NO_ACTION; break; default: $error-type = self::EXCEPTION_OTHER; break; } In the default case, you'd then need to look at the exception itself. Try this: switch ($error-type) { case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER: case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION: // these are basically 404s... display some message to that // effect... break; default: $eClass = get_class($error-exception); switch ($eClass) { case 'Zend_Auth_Adapter_Exception': // authentication error... break; case ... } } However, probably a better method would be to do a try/catch around the call throwing the exception, and forwarding to a custom error from there: try { $identity = $auth-getIdentity(); } catch (Zend_Auth_Adapter_Exception $e) { return $this-_forward('auth', 'error', 'default'); } The ErrorHandler plugin is primarily for routing dispatch exceptions (i.e., controller or action not found) and unhandled application exceptions. You should try and handle exceptions in your applications as much as possible, particularly if you will be wanting to do custom error reporting for them. Don't go overboard, though -- database errors are typically an edge case when catching exceptions, so allowing those to bubble up to the ErrorHandler plugin makes sense. However, Your auth example is a prime candidate for targetted error handling within the application.