-1

In my page (with CakePHP 2.4), I added a functionality for when there is an ajax request, if the user is not logged in, then throws a 401 Unauthorized HTTP error so ajax can catch it and knows that has to redirect to login. But the problem is that ErrorHandler doesn't catch it, and it shows it as Uncaught exception:

PHP Fatal error: Uncaught exception 'UnauthorizedException' with message 'Su sesión ha terminado. Por favor ingrese nuevamente' in D:\wamp\www\app\Controller\AppController.php:121 

The fact is that I modified some values to implement my own handler, but then I changed my mind and I reverted back to defaults, so probably I missed something. And now doesn't catch any kind of error, even 404 ones, and from ajax and normal http requests.

Here's my AppController::beforeFilter code:

public function beforeFilter()
{
    if($this->Session->check('login.language'))
    {
        Configure::write('Config.language', $this->Session->read('login.language'));
    }
    else
    {
        Configure::write('Config.language', "spa");
    }
    parent::beforeFilter();
    //Here is the login check part
    if(!$this->Auth->user('id') && $this->request->is('ajax') && !(in_array($this->request->params['action'], array('login', 'cambiar_idioma'))))
    {
        throw new UnauthorizedException(__("Su sesión ha terminado. Por favor ingrese nuevamente"));
    }

}

The handlers config in core.php:

Configure::write('Error', array(
    'handler' => 'ErrorHandler::handleError',
    'level' => E_ALL & ~E_DEPRECATED & ~E_STRICT,
    'trace' => true
));

Configure::write('Exception', array(
    'handler' => 'ErrorHandler::handleException',
    'renderer' => 'ExceptionRenderer',
    'log' => true
));

Configure::write('debug', 2);

So, any ideas why is it not catching any exceptions?

4

1 回答 1

0

终于得到了答案。重新安装 Cake 后,逐个文件移动页面上的所有内容,我发现该jpGraph库与 Cake 错误处理冲突。由于我在文件顶部导入了库,因此每个请求都搞砸了,因此我将其移至其各自的功能并按预期工作。

于 2014-04-02T14:55:42.713 回答