1

I have the security component in one of my comment submit forms.. Now, when something goes wrong, and the blackhole callback is called, I want to throw an InternalErrorException with a custom message, such as:

 throw new InternalErrorException('You have tried to submit a comment whose security token is either invalid or expired. Please try again by reloading the blog post and commenting again. Thank you.');

The thing is that the message does not get displayed in production mode (debug == 0). What do I have to do to show the message to the user instead of "An Internal Error Has Occurred"?

This is my error500.ctp: http://pastebin.com/t9NuzuqS

4

2 に答える 2

1

those "messages" are only for development purposes. in live mode (debug 0) the visitor should not get any of those descriptive issue descriptions you got on your server. he wouldnt understand it anyway. so in live mode there is only a 404/5xx thrown and thats it. but your message will be error-logged for you (as developer) to find afterwards.

于 2012-11-23T10:48:32.767 に答える
1

What you can probably do is overwrite the blackHole action of the Security component.

Currently you can find it in cakephp\lib\Cake\Controller\Component\SecurityComponent. You should create a SecurityComponent in your Controller\Component folder and overwrite this method as you wish:

public function blackHole(Controller $controller, $error = '') {
    if ($this->blackHoleCallback == null) {
        throw new BadRequestException(__d('cake_dev', 'The request has been black-holed'));
    } else {
        return $this->_callback($controller, $this->blackHoleCallback, array($error));
    }
}

You can throw the same exception with another message. This exceptions will be seen for users even with debug set to 0 as detailed on the documentation

于 2012-11-23T11:48:46.407 に答える