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.