Skip to content
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

Closed
niden opened this issue Sep 9, 2012 · 5 comments
Closed

[NFR] Default error handler #66

niden opened this issue Sep 9, 2012 · 5 comments
Milestone

Comments

@niden
Copy link
Member

niden commented Sep 9, 2012

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

@niden
Copy link
Member Author

niden commented Sep 11, 2012

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

@brandonlamb
Copy link

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?

@johnnyajax
Copy link

+1 for error handler.
This is not normal 404 response for production website: http://phalconphp.com/indexxxx
And i can't figure out where and how i can add internal forward like:
$app->dispatcher->forward(array("controller" => "index", "action" => "error404"));

@niden
Copy link
Member Author

niden commented Oct 17, 2012

Right now the main script of the website as it can be seen in github
encapsulates operations with a try catch.

When an exception happens it only prints out the error message from the
exception.

Working a bit on the try catch code could trap and display things better
until this feature is developed. :)
On Oct 16, 2012 8:07 PM, "JohnnyAjax" [email protected] wrote:

+1 for error handler.
This is not normal 404 response for production website:
http://phalconphp.com/indexxxx


Reply to this email directly or view it on GitHubhttps://github.com//issues/66#issuecomment-9511773.

@phalcon
Copy link
Collaborator

phalcon commented Oct 19, 2012

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;
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants