-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NFR] Default error handler #66
Comments
Feedback by Nesbert in the google groups: +1 for Error handler... in the interim here is an example of how am dealing with issue https://gist.github.com/3701633#L113 |
Another +1 for this. With options to configure per module too, set error handler to module, controller, action and pass in exception object or something? |
+1 for error handler. |
Right now the main script of the website as it can be seen in github When an exception happens it only prints out the error message from the Working a bit on the try catch code could trap and display things better
|
0.6.0 now supports an error handler for exceptions produced by the dispatcher $di->set('dispatcher', function(){
//Create/Get an EventManager
$eventsManager = new Phalcon\Events\Manager();
//Attach a listener
$eventsManager->attach("dispatch", function($event, $dispatcher, $exception) {
//The controller exists but the action not
if ($event->getType() == 'beforeNotFoundAction') {
$dispatcher->forward(array(
'controller' => 'index',
'action' => 'show404'
));
return false;
}
//Alternative way, controller or action doesn't exists
if ($event->getType() == 'beforeException') {
switch ($exception->getCode()){
case Phalcon\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
case Phalcon\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
$dispatcher->forward(array(
'controller' => 'index',
'action' => 'show404'
));
return false;
}
}
});
$dispatcher = new Phalcon\Mvc\Dispatcher();
$dispatcher->setEventsManager($eventsManager);
return $dispatcher;
}); |
Error handler - it would be cool if instead of try catch block I could define where my exceptions should be routed to and where I could display a proper 404/500 page to the user. It could be done by set_exception_handle but it would be even cooler if Phalcon would handle it internally.
i.e. default route /error/index
The text was updated successfully, but these errors were encountered: