{"action":"opened","issue":{"url":"https://api.github.com/repos/cakephp/cakephp/issues/9931","repository_url":"https://api.github.com/repos/cakephp/cakephp","labels_url":"https://api.github.com/repos/cakephp/cakephp/issues/9931/labels{/name}","comments_url":"https://api.github.com/repos/cakephp/cakephp/issues/9931/comments","events_url":"https://api.github.com/repos/cakephp/cakephp/issues/9931/events","html_url":"https://github.com/cakephp/cakephp/issues/9931","id":197945987,"number":9931,"title":"Extending the error handler doesn't work for developer thrown exceptions","user":{"login":"ebrigham1","id":7337543,"avatar_url":"https://avatars.githubusercontent.com/u/7337543?v=3","gravatar_id":"","url":"https://api.github.com/users/ebrigham1","html_url":"https://github.com/ebrigham1","followers_url":"https://api.github.com/users/ebrigham1/followers","following_url":"https://api.github.com/users/ebrigham1/following{/other_user}","gists_url":"https://api.github.com/users/ebrigham1/gists{/gist_id}","starred_url":"https://api.github.com/users/ebrigham1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ebrigham1/subscriptions","organizations_url":"https://api.github.com/users/ebrigham1/orgs","repos_url":"https://api.github.com/users/ebrigham1/repos","events_url":"https://api.github.com/users/ebrigham1/events{/privacy}","received_events_url":"https://api.github.com/users/ebrigham1/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-12-29T02:54:17Z","updated_at":"2016-12-29T02:54:17Z","closed_at":null,"body":"This is a (multiple allowed):\r\n\r\n* [ ] bug\r\n* [x] enhancement\r\n* [x] feature-discussion (RFC)\r\n\r\n* CakePHP Version: 3.3.10\r\n\r\nI'm new to cake but not new to programming. I'm trying to extend the cake error handler to add additional behaviors. I'm looking to do things like email the dev team with exception information, or contact an API to generate a ticket, ect.\r\n```php\r\nnamespace App\\Error;\r\n\r\nuse Cake\\Error\\ErrorHandler as CakeErrorHandler;\r\nuse Exception;\r\n\r\nclass ErrorHandler extends CakeErrorHandler\r\n{\r\n    public function handleException(Exception $exception)\r\n    {\r\n        // Add emailing exception functionality\r\n        $this->_emailException($exception);\r\n        // Use parent functionality to log/display exception ect\r\n        parent::handleException($exception);\r\n    }\r\n    // Code to email exceptions, throttle emails,\r\n    // skip emails by exception class, ect\r\n}\r\n```\r\nThe issue I'm running into is that this class extension will work for all fatal errors that get wrapped up into exceptions, however it doesn't work for exceptions that a developer might choose to throw in the application since they seem to be caught, logged and displayed via [Cake\\Error\\Middleware\\ErrorHandlerMiddleware](https://github.com/cakephp/cakephp/blob/master/src/Error/Middleware/ErrorHandlerMiddleware.php) rather than [Cake\\Error\\ErrorHandler](https://github.com/cakephp/cakephp/blob/master/src/Error/ErrorHandler.php)\r\n\r\nFor instance:\r\n```php\r\nnamespace App\\Controller;\r\n\r\nuse App\\Controller\\AppController;\r\n\r\nclass PaymentController extends AppController\r\n{\r\n    public function fulfillOrder()\r\n    {\r\n        // Process payment was successful\r\n        // Attempt to fulfill payment, requires API calls to external resources\r\n        // that fail\r\n        throw new App\\Exception\\FulfillmentFailed('Order failed');\r\n    }\r\n}\r\n```\r\nWhy aren't these types of exceptions also caught and handled by Cake\\Error\\ErrorHandler? When removing Cake\\Error\\Middleware\\ErrorHandlerMiddleware from my local application middleware stack defined in App/Application I notice no difference in logging or rendering of those types of exceptions. So it seems like its largely doing the same job Cake\\Error\\ErrorHandler already does. Yet it forces me to also extend and override the middleware if I want to be able to add my functionality to those types of exceptions. Is there a reason these types of exceptions are caught in this manner rather than being allowed to bubble through to Cake\\Error\\ErrorHandler?"}}
{"actor":{"display_login":"ebrigham1"}}