{"action":"created","comment":{"url":"https://api.github.com/repos/sdogruyol/kemal/pulls/comments/52841059","id":52841059,"diff_hunk":"@@ -24,21 +24,14 @@ class Kemal::RouteHandler < HTTP::Handler\n \n   # Processes the route if it's a match. Otherwise renders 404.\n   def process_request(context)\n-    url = context.request.path.not_nil!\n+    raise NilPathException.new unless context.request.path","path":"src/kemal/route_handler.cr","position":5,"original_position":5,"commit_id":"463259c41a9d7d6d39d0a4cf822cce1b1b99d0ed","original_commit_id":"706587a7c54cf42b5eff402ce7cc42d539ad8b91","user":{"login":"jmoriau","id":13310881,"avatar_url":"https://avatars.githubusercontent.com/u/13310881?v=3","gravatar_id":"","url":"https://api.github.com/users/jmoriau","html_url":"https://github.com/jmoriau","followers_url":"https://api.github.com/users/jmoriau/followers","following_url":"https://api.github.com/users/jmoriau/following{/other_user}","gists_url":"https://api.github.com/users/jmoriau/gists{/gist_id}","starred_url":"https://api.github.com/users/jmoriau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmoriau/subscriptions","organizations_url":"https://api.github.com/users/jmoriau/orgs","repos_url":"https://api.github.com/users/jmoriau/repos","events_url":"https://api.github.com/users/jmoriau/events{/privacy}","received_events_url":"https://api.github.com/users/jmoriau/received_events","type":"User","site_admin":false},"body":"Ah ok I understand it now I'll remove it then.","created_at":"2016-02-14T11:17:20Z","updated_at":"2016-02-14T11:17:20Z","html_url":"https://github.com/sdogruyol/kemal/pull/92#discussion_r52841059","pull_request_url":"https://api.github.com/repos/sdogruyol/kemal/pulls/92","_links":{"self":{"href":"https://api.github.com/repos/sdogruyol/kemal/pulls/comments/52841059"},"html":{"href":"https://github.com/sdogruyol/kemal/pull/92#discussion_r52841059"},"pull_request":{"href":"https://api.github.com/repos/sdogruyol/kemal/pulls/92"}}},"pull_request":{"url":"https://api.github.com/repos/sdogruyol/kemal/pulls/92","id":59292670,"html_url":"https://github.com/sdogruyol/kemal/pull/92","diff_url":"https://github.com/sdogruyol/kemal/pull/92.diff","patch_url":"https://github.com/sdogruyol/kemal/pull/92.patch","issue_url":"https://api.github.com/repos/sdogruyol/kemal/issues/92","number":92,"state":"open","locked":false,"title":"decoupled errors from route-handler","user":{"login":"jmoriau","id":13310881,"avatar_url":"https://avatars.githubusercontent.com/u/13310881?v=3","gravatar_id":"","url":"https://api.github.com/users/jmoriau","html_url":"https://github.com/jmoriau","followers_url":"https://api.github.com/users/jmoriau/followers","following_url":"https://api.github.com/users/jmoriau/following{/other_user}","gists_url":"https://api.github.com/users/jmoriau/gists{/gist_id}","starred_url":"https://api.github.com/users/jmoriau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmoriau/subscriptions","organizations_url":"https://api.github.com/users/jmoriau/orgs","repos_url":"https://api.github.com/users/jmoriau/repos","events_url":"https://api.github.com/users/jmoriau/events{/privacy}","received_events_url":"https://api.github.com/users/jmoriau/received_events","type":"User","site_admin":false},"body":"Hi,\r\n\r\nWhile playing with my logger I realized that the error handling wasn't very flexible, so I tried to decouple it from the RouteHandler.\r\nNow a custom logger will receive exceptions messages and we'll be able to provide a custom `ErrorHandler`.\r\n\r\nAlso I don't understand well how the spec works so for now 2 tests are failing:\r\n - `spec/route_handler.cr L111`: Kemal::RouteHandler renders 404 on not found\r\n - `spec/route_handler.cr L191`: Kemal::RouteHandler can't process HTTP HEAD requests for undefined GET routes\r\n\r\nBut when I try it with a live instance everything works the same.\r\n\r\nHere are all the changes I made:\r\n\r\nconfig.cr:\r\n- changed `setup_logging` to only instantiate and add the CommonLogger to the handlers if no logger has already been instantiated.\r\nThat way the CommonLogger is no longer added if another logger is provided.\r\n- added `setup_error_handler` to use a custom error handler if provided.\r\n- added `@always_rescue` so that we can choose if we want to always rescue or not.\r\n- added `@error_handler` so that we can provide a custom error handler.\r\n\r\n\r\nkemal.cr:\r\n- Added `setup_error_handler`\r\n- The current behavior is to rescue only the exceptions raised in the `RouteHandler`, so to keep this behavior, the `CommonErrorHandler` is placed just before the RouteHandler middleware, I wasn’t sure if it would be better to rescue exceptions that could be raised from previous middleware but I thought each middleware before the CommonErrorLogger should always catch their own exceptions and not `call_next` if the current state is not stable.\r\n\r\nroute_handler.cr\r\n- in `process_request` there was an unused `url` local variable.\r\n- removed the rescue and instead added 2 exceptions to raise\r\n\r\n\r\nLet me know what you think :smile: ","created_at":"2016-02-14T10:53:40Z","updated_at":"2016-02-14T11:17:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7f0baeb02b93394d4350cf7864549b02c4da68d3","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/sdogruyol/kemal/pulls/92/commits","review_comments_url":"https://api.github.com/repos/sdogruyol/kemal/pulls/92/comments","review_comment_url":"https://api.github.com/repos/sdogruyol/kemal/pulls/comments{/number}","comments_url":"https://api.github.com/repos/sdogruyol/kemal/issues/92/comments","statuses_url":"https://api.github.com/repos/sdogruyol/kemal/statuses/463259c41a9d7d6d39d0a4cf822cce1b1b99d0ed","head":{"label":"jmoriau:decouple-error-hanlder","ref":"decouple-error-hanlder","sha":"463259c41a9d7d6d39d0a4cf822cce1b1b99d0ed","user":{"login":"jmoriau","id":13310881,"avatar_url":"https://avatars.githubusercontent.com/u/13310881?v=3","gravatar_id":"","url":"https://api.github.com/users/jmoriau","html_url":"https://github.com/jmoriau","followers_url":"https://api.github.com/users/jmoriau/followers","following_url":"https://api.github.com/users/jmoriau/following{/other_user}","gists_url":"https://api.github.com/users/jmoriau/gists{/gist_id}","starred_url":"https://api.github.com/users/jmoriau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmoriau/subscriptions","organizations_url":"https://api.github.com/users/jmoriau/orgs","repos_url":"https://api.github.com/users/jmoriau/repos","events_url":"https://api.github.com/users/jmoriau/events{/privacy}","received_events_url":"https://api.github.com/users/jmoriau/received_events","type":"User","site_admin":false},"repo":{"id":51688553,"name":"kemal","full_name":"jmoriau/kemal","owner":{"login":"jmoriau","id":13310881,"avatar_url":"https://avatars.githubusercontent.com/u/13310881?v=3","gravatar_id":"","url":"https://api.github.com/users/jmoriau","html_url":"https://github.com/jmoriau","followers_url":"https://api.github.com/users/jmoriau/followers","following_url":"https://api.github.com/users/jmoriau/following{/other_user}","gists_url":"https://api.github.com/users/jmoriau/gists{/gist_id}","starred_url":"https://api.github.com/users/jmoriau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmoriau/subscriptions","organizations_url":"https://api.github.com/users/jmoriau/orgs","repos_url":"https://api.github.com/users/jmoriau/repos","events_url":"https://api.github.com/users/jmoriau/events{/privacy}","received_events_url":"https://api.github.com/users/jmoriau/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jmoriau/kemal","description":"Lightning Fast, Super Simple web framework for Crystal","fork":true,"url":"https://api.github.com/repos/jmoriau/kemal","forks_url":"https://api.github.com/repos/jmoriau/kemal/forks","keys_url":"https://api.github.com/repos/jmoriau/kemal/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jmoriau/kemal/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jmoriau/kemal/teams","hooks_url":"https://api.github.com/repos/jmoriau/kemal/hooks","issue_events_url":"https://api.github.com/repos/jmoriau/kemal/issues/events{/number}","events_url":"https://api.github.com/repos/jmoriau/kemal/events","assignees_url":"https://api.github.com/repos/jmoriau/kemal/assignees{/user}","branches_url":"https://api.github.com/repos/jmoriau/kemal/branches{/branch}","tags_url":"https://api.github.com/repos/jmoriau/kemal/tags","blobs_url":"https://api.github.com/repos/jmoriau/kemal/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jmoriau/kemal/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jmoriau/kemal/git/refs{/sha}","trees_url":"https://api.github.com/repos/jmoriau/kemal/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jmoriau/kemal/statuses/{sha}","languages_url":"https://api.github.com/repos/jmoriau/kemal/languages","stargazers_url":"https://api.github.com/repos/jmoriau/kemal/stargazers","contributors_url":"https://api.github.com/repos/jmoriau/kemal/contributors","subscribers_url":"https://api.github.com/repos/jmoriau/kemal/subscribers","subscription_url":"https://api.github.com/repos/jmoriau/kemal/subscription","commits_url":"https://api.github.com/repos/jmoriau/kemal/commits{/sha}","git_commits_url":"https://api.github.com/repos/jmoriau/kemal/git/commits{/sha}","comments_url":"https://api.github.com/repos/jmoriau/kemal/comments{/number}","issue_comment_url":"https://api.github.com/repos/jmoriau/kemal/issues/comments{/number}","contents_url":"https://api.github.com/repos/jmoriau/kemal/contents/{+path}","compare_url":"https://api.github.com/repos/jmoriau/kemal/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jmoriau/kemal/merges","archive_url":"https://api.github.com/repos/jmoriau/kemal/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jmoriau/kemal/downloads","issues_url":"https://api.github.com/repos/jmoriau/kemal/issues{/number}","pulls_url":"https://api.github.com/repos/jmoriau/kemal/pulls{/number}","milestones_url":"https://api.github.com/repos/jmoriau/kemal/milestones{/number}","notifications_url":"https://api.github.com/repos/jmoriau/kemal/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jmoriau/kemal/labels{/name}","releases_url":"https://api.github.com/repos/jmoriau/kemal/releases{/id}","deployments_url":"https://api.github.com/repos/jmoriau/kemal/deployments","created_at":"2016-02-14T09:34:17Z","updated_at":"2016-02-14T09:34:18Z","pushed_at":"2016-02-14T11:14:12Z","git_url":"git://github.com/jmoriau/kemal.git","ssh_url":"git@github.com:jmoriau/kemal.git","clone_url":"https://github.com/jmoriau/kemal.git","svn_url":"https://github.com/jmoriau/kemal","homepage":"http://kemalcr.com","size":240,"stargazers_count":0,"watchers_count":0,"language":"Crystal","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"sdogruyol:master","ref":"master","sha":"88aa9cd49741e524b8af8c300fd566259995b22f","user":{"login":"sdogruyol","id":990485,"avatar_url":"https://avatars.githubusercontent.com/u/990485?v=3","gravatar_id":"","url":"https://api.github.com/users/sdogruyol","html_url":"https://github.com/sdogruyol","followers_url":"https://api.github.com/users/sdogruyol/followers","following_url":"https://api.github.com/users/sdogruyol/following{/other_user}","gists_url":"https://api.github.com/users/sdogruyol/gists{/gist_id}","starred_url":"https://api.github.com/users/sdogruyol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sdogruyol/subscriptions","organizations_url":"https://api.github.com/users/sdogruyol/orgs","repos_url":"https://api.github.com/users/sdogruyol/repos","events_url":"https://api.github.com/users/sdogruyol/events{/privacy}","received_events_url":"https://api.github.com/users/sdogruyol/received_events","type":"User","site_admin":false},"repo":{"id":44826364,"name":"kemal","full_name":"sdogruyol/kemal","owner":{"login":"sdogruyol","id":990485,"avatar_url":"https://avatars.githubusercontent.com/u/990485?v=3","gravatar_id":"","url":"https://api.github.com/users/sdogruyol","html_url":"https://github.com/sdogruyol","followers_url":"https://api.github.com/users/sdogruyol/followers","following_url":"https://api.github.com/users/sdogruyol/following{/other_user}","gists_url":"https://api.github.com/users/sdogruyol/gists{/gist_id}","starred_url":"https://api.github.com/users/sdogruyol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sdogruyol/subscriptions","organizations_url":"https://api.github.com/users/sdogruyol/orgs","repos_url":"https://api.github.com/users/sdogruyol/repos","events_url":"https://api.github.com/users/sdogruyol/events{/privacy}","received_events_url":"https://api.github.com/users/sdogruyol/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sdogruyol/kemal","description":"Lightning Fast, Super Simple web framework for Crystal","fork":false,"url":"https://api.github.com/repos/sdogruyol/kemal","forks_url":"https://api.github.com/repos/sdogruyol/kemal/forks","keys_url":"https://api.github.com/repos/sdogruyol/kemal/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sdogruyol/kemal/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sdogruyol/kemal/teams","hooks_url":"https://api.github.com/repos/sdogruyol/kemal/hooks","issue_events_url":"https://api.github.com/repos/sdogruyol/kemal/issues/events{/number}","events_url":"https://api.github.com/repos/sdogruyol/kemal/events","assignees_url":"https://api.github.com/repos/sdogruyol/kemal/assignees{/user}","branches_url":"https://api.github.com/repos/sdogruyol/kemal/branches{/branch}","tags_url":"https://api.github.com/repos/sdogruyol/kemal/tags","blobs_url":"https://api.github.com/repos/sdogruyol/kemal/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sdogruyol/kemal/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sdogruyol/kemal/git/refs{/sha}","trees_url":"https://api.github.com/repos/sdogruyol/kemal/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sdogruyol/kemal/statuses/{sha}","languages_url":"https://api.github.com/repos/sdogruyol/kemal/languages","stargazers_url":"https://api.github.com/repos/sdogruyol/kemal/stargazers","contributors_url":"https://api.github.com/repos/sdogruyol/kemal/contributors","subscribers_url":"https://api.github.com/repos/sdogruyol/kemal/subscribers","subscription_url":"https://api.github.com/repos/sdogruyol/kemal/subscription","commits_url":"https://api.github.com/repos/sdogruyol/kemal/commits{/sha}","git_commits_url":"https://api.github.com/repos/sdogruyol/kemal/git/commits{/sha}","comments_url":"https://api.github.com/repos/sdogruyol/kemal/comments{/number}","issue_comment_url":"https://api.github.com/repos/sdogruyol/kemal/issues/comments{/number}","contents_url":"https://api.github.com/repos/sdogruyol/kemal/contents/{+path}","compare_url":"https://api.github.com/repos/sdogruyol/kemal/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sdogruyol/kemal/merges","archive_url":"https://api.github.com/repos/sdogruyol/kemal/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sdogruyol/kemal/downloads","issues_url":"https://api.github.com/repos/sdogruyol/kemal/issues{/number}","pulls_url":"https://api.github.com/repos/sdogruyol/kemal/pulls{/number}","milestones_url":"https://api.github.com/repos/sdogruyol/kemal/milestones{/number}","notifications_url":"https://api.github.com/repos/sdogruyol/kemal/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sdogruyol/kemal/labels{/name}","releases_url":"https://api.github.com/repos/sdogruyol/kemal/releases{/id}","deployments_url":"https://api.github.com/repos/sdogruyol/kemal/deployments","created_at":"2015-10-23T16:56:29Z","updated_at":"2016-02-13T12:58:34Z","pushed_at":"2016-02-14T11:14:13Z","git_url":"git://github.com/sdogruyol/kemal.git","ssh_url":"git@github.com:sdogruyol/kemal.git","clone_url":"https://github.com/sdogruyol/kemal.git","svn_url":"https://github.com/sdogruyol/kemal","homepage":"http://kemalcr.com","size":237,"stargazers_count":440,"watchers_count":440,"language":"Crystal","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":26,"mirror_url":null,"open_issues_count":7,"forks":26,"open_issues":7,"watchers":440,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/sdogruyol/kemal/pulls/92"},"html":{"href":"https://github.com/sdogruyol/kemal/pull/92"},"issue":{"href":"https://api.github.com/repos/sdogruyol/kemal/issues/92"},"comments":{"href":"https://api.github.com/repos/sdogruyol/kemal/issues/92/comments"},"review_comments":{"href":"https://api.github.com/repos/sdogruyol/kemal/pulls/92/comments"},"review_comment":{"href":"https://api.github.com/repos/sdogruyol/kemal/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/sdogruyol/kemal/pulls/92/commits"},"statuses":{"href":"https://api.github.com/repos/sdogruyol/kemal/statuses/463259c41a9d7d6d39d0a4cf822cce1b1b99d0ed"}}}}