{"action":"opened","issue":{"url":"https://api.github.com/repos/silexphp/Silex/issues/1424","repository_url":"https://api.github.com/repos/silexphp/Silex","labels_url":"https://api.github.com/repos/silexphp/Silex/issues/1424/labels{/name}","comments_url":"https://api.github.com/repos/silexphp/Silex/issues/1424/comments","events_url":"https://api.github.com/repos/silexphp/Silex/issues/1424/events","html_url":"https://github.com/silexphp/Silex/issues/1424","id":178832907,"number":1424,"title":"Documentation about register ","user":{"login":"mindcreations","id":8978078,"avatar_url":"https://avatars.githubusercontent.com/u/8978078?v=3","gravatar_id":"","url":"https://api.github.com/users/mindcreations","html_url":"https://github.com/mindcreations","followers_url":"https://api.github.com/users/mindcreations/followers","following_url":"https://api.github.com/users/mindcreations/following{/other_user}","gists_url":"https://api.github.com/users/mindcreations/gists{/gist_id}","starred_url":"https://api.github.com/users/mindcreations/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mindcreations/subscriptions","organizations_url":"https://api.github.com/users/mindcreations/orgs","repos_url":"https://api.github.com/users/mindcreations/repos","events_url":"https://api.github.com/users/mindcreations/events{/privacy}","received_events_url":"https://api.github.com/users/mindcreations/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-09-23T09:49:15Z","updated_at":"2016-09-23T09:49:15Z","closed_at":null,"body":"Documentation about setting a custom error handler [here] (http://silex.sensiolabs.org/doc/master/usage.html#error-handlers) states with this example how to set a custom error handler:\r\n\r\n```php\r\n$app->error(function (\\Exception $e, Request $request, $code) {\r\n    return new Response('We are sorry, but something went terribly wrong.');\r\n});\r\n```\r\n\r\nI've tried and returns:\r\n\r\n:collision: _Catchable fatal error: Argument 2 passed to {closure}() must be an instance of Symfony\\Component\\HttpFoundation\\Request, integer given in ..._ \r\n\r\nI've fixed the error by coding this way:\r\n\r\n```php\r\n$app->error(function (\\Exception $e) {\r\n    return new Response('We are sorry, but something went terribly wrong.');\r\n});\r\n```\r\neven the following example in the doc is wrong IMHO:\r\n\r\n```php\r\n$app->error(function (\\Exception $e, Request $request, $code) {\r\n    switch ($code) {\r\n        case 404:\r\n            $message = 'The requested page could not be found.';\r\n            break;\r\n        default:\r\n            $message = 'We are sorry, but something went terribly wrong.';\r\n    }\r\n    return new Response($message);\r\n});\r\n```\r\n\r\nThe working code I use is:\r\n\r\n```php\r\n$app->error(function (\\Exception $e) {\r\n    switch ($e->getStatusCode()) {\r\n        case 404:\r\n            $message = 'The requested page could not be found.';\r\n            break;\r\n        case 400:\r\n            $message = $e->getMessage();\r\n            break;\r\n        default:\r\n            $message = 'We are sorry, but something went terribly wrong.';\r\n    }\r\n    return new Response($message);\r\n});\r\n```\r\n\r\nI think documentation should be fixed or... please tell me what I've not understood."}}
{"actor":{"display_login":"mindcreations"}}