{"action":"created","comment":{"url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/pulls/comments/176946109","pull_request_review_id":106735761,"id":176946109,"diff_hunk":"@@ -1,61 +1,79 @@\n import Vapor\n-import HTTP\n+import Leaf\n \n-public final class LeafErrorMiddleware: Middleware {\n-    let log: LogProtocol\n+/// Captures all errors and transforms them into an internal server error.\n+public final class LeafErrorMiddleware: Middleware, Service {\n+    /// The environment to respect when presenting errors.\n     let environment: Environment\n-    let viewRenderer: ViewRenderer\n-    public init(environment: Environment, log: LogProtocol, viewRenderer: ViewRenderer) {\n-        self.log = log\n+\n+    /// Log destination\n+    let log: Logger\n+\n+    /// Create a new ErrorMiddleware for the supplied environment.\n+    public init(environment: Environment, log: Logger) {\n         self.environment = environment\n-        self.viewRenderer = viewRenderer\n+        self.log = log\n     }\n \n-    public func respond(to req: Request, chainingTo next: Responder) throws -> Response {\n-        do {\n-            return try next.respond(to: req)\n-        } catch {\n-            log.error(error)\n-            return make(with: req, for: error)\n-        }\n-    }\n+    /// See `Middleware.respond`\n+    public func respond(to req: Request, chainingTo next: Responder) throws -> Future<Response> {\n+        let renderer = try req.make(LeafRenderer.self)\n+        let promise = req.eventLoop.newPromise(Response.self)\n+\n+        func handleError(with status: HTTPStatus) {\n+            if status == .notFound {\n+                do {\n+                    try renderer\n+                        .render(\"404\")\n+                        .encode(for: req)\n+                        .do { res in\n+                            res.http.status = status\n+                            promise.succeed(result: res)\n+                    }\n+                } catch { /* swallow so we return the default view */ }\n+            }\n \n-    public func make(with req: Request, for error: Error) -> Response {\n-        let status: Status = Status(error)\n-        if status == .notFound {","path":"Sources/LeafErrorMiddleware/LeafErrorMiddleware.swift","position":53,"original_position":53,"commit_id":"31b18471ae421215addee5a57adc4efb238eff23","original_commit_id":"31b18471ae421215addee5a57adc4efb238eff23","user":{"login":"0xTim","id":9938337,"avatar_url":"https://avatars3.githubusercontent.com/u/9938337?v=4","gravatar_id":"","url":"https://api.github.com/users/0xTim","html_url":"https://github.com/0xTim","followers_url":"https://api.github.com/users/0xTim/followers","following_url":"https://api.github.com/users/0xTim/following{/other_user}","gists_url":"https://api.github.com/users/0xTim/gists{/gist_id}","starred_url":"https://api.github.com/users/0xTim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/0xTim/subscriptions","organizations_url":"https://api.github.com/users/0xTim/orgs","repos_url":"https://api.github.com/users/0xTim/repos","events_url":"https://api.github.com/users/0xTim/events{/privacy}","received_events_url":"https://api.github.com/users/0xTim/received_events","type":"User","site_admin":false},"body":"There are two templates that the middleware renders - one for 404 errors and one for 500 errors (or everything else) - that's why the check is here","created_at":"2018-03-25T16:39:43Z","updated_at":"2018-03-25T16:39:43Z","html_url":"https://github.com/brokenhandsio/leaf-error-middleware/pull/4#discussion_r176946109","pull_request_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/pulls/4","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/pulls/comments/176946109"},"html":{"href":"https://github.com/brokenhandsio/leaf-error-middleware/pull/4#discussion_r176946109"},"pull_request":{"href":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/pulls/4"}},"in_reply_to_id":176943934},"pull_request":{"url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/pulls/4","id":177261007,"html_url":"https://github.com/brokenhandsio/leaf-error-middleware/pull/4","diff_url":"https://github.com/brokenhandsio/leaf-error-middleware/pull/4.diff","patch_url":"https://github.com/brokenhandsio/leaf-error-middleware/pull/4.patch","issue_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/issues/4","number":4,"state":"open","locked":false,"title":"Vapor3 (Same as ErrorMiddleware)","user":{"login":"bre7","id":3183848,"avatar_url":"https://avatars3.githubusercontent.com/u/3183848?v=4","gravatar_id":"","url":"https://api.github.com/users/bre7","html_url":"https://github.com/bre7","followers_url":"https://api.github.com/users/bre7/followers","following_url":"https://api.github.com/users/bre7/following{/other_user}","gists_url":"https://api.github.com/users/bre7/gists{/gist_id}","starred_url":"https://api.github.com/users/bre7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bre7/subscriptions","organizations_url":"https://api.github.com/users/bre7/orgs","repos_url":"https://api.github.com/users/bre7/repos","events_url":"https://api.github.com/users/bre7/events{/privacy}","received_events_url":"https://api.github.com/users/bre7/received_events","type":"User","site_admin":false},"body":"Not sure why but valid requests aren't resolved correctly","created_at":"2018-03-24T21:58:49Z","updated_at":"2018-03-25T16:39:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a4eda16c9a295e2ddb56a1830be9e2a91be01988","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/pulls/4/commits","review_comments_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/pulls/4/comments","review_comment_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/pulls/comments{/number}","comments_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/issues/4/comments","statuses_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/statuses/31b18471ae421215addee5a57adc4efb238eff23","head":{"label":"bre7:patch-2","ref":"patch-2","sha":"31b18471ae421215addee5a57adc4efb238eff23","user":{"login":"bre7","id":3183848,"avatar_url":"https://avatars3.githubusercontent.com/u/3183848?v=4","gravatar_id":"","url":"https://api.github.com/users/bre7","html_url":"https://github.com/bre7","followers_url":"https://api.github.com/users/bre7/followers","following_url":"https://api.github.com/users/bre7/following{/other_user}","gists_url":"https://api.github.com/users/bre7/gists{/gist_id}","starred_url":"https://api.github.com/users/bre7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bre7/subscriptions","organizations_url":"https://api.github.com/users/bre7/orgs","repos_url":"https://api.github.com/users/bre7/repos","events_url":"https://api.github.com/users/bre7/events{/privacy}","received_events_url":"https://api.github.com/users/bre7/received_events","type":"User","site_admin":false},"repo":{"id":126531277,"name":"leaf-error-middleware","full_name":"bre7/leaf-error-middleware","owner":{"login":"bre7","id":3183848,"avatar_url":"https://avatars3.githubusercontent.com/u/3183848?v=4","gravatar_id":"","url":"https://api.github.com/users/bre7","html_url":"https://github.com/bre7","followers_url":"https://api.github.com/users/bre7/followers","following_url":"https://api.github.com/users/bre7/following{/other_user}","gists_url":"https://api.github.com/users/bre7/gists{/gist_id}","starred_url":"https://api.github.com/users/bre7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bre7/subscriptions","organizations_url":"https://api.github.com/users/bre7/orgs","repos_url":"https://api.github.com/users/bre7/repos","events_url":"https://api.github.com/users/bre7/events{/privacy}","received_events_url":"https://api.github.com/users/bre7/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bre7/leaf-error-middleware","description":"Serve up custom 404 and server error pages for your Vapor App","fork":true,"url":"https://api.github.com/repos/bre7/leaf-error-middleware","forks_url":"https://api.github.com/repos/bre7/leaf-error-middleware/forks","keys_url":"https://api.github.com/repos/bre7/leaf-error-middleware/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bre7/leaf-error-middleware/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bre7/leaf-error-middleware/teams","hooks_url":"https://api.github.com/repos/bre7/leaf-error-middleware/hooks","issue_events_url":"https://api.github.com/repos/bre7/leaf-error-middleware/issues/events{/number}","events_url":"https://api.github.com/repos/bre7/leaf-error-middleware/events","assignees_url":"https://api.github.com/repos/bre7/leaf-error-middleware/assignees{/user}","branches_url":"https://api.github.com/repos/bre7/leaf-error-middleware/branches{/branch}","tags_url":"https://api.github.com/repos/bre7/leaf-error-middleware/tags","blobs_url":"https://api.github.com/repos/bre7/leaf-error-middleware/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bre7/leaf-error-middleware/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bre7/leaf-error-middleware/git/refs{/sha}","trees_url":"https://api.github.com/repos/bre7/leaf-error-middleware/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bre7/leaf-error-middleware/statuses/{sha}","languages_url":"https://api.github.com/repos/bre7/leaf-error-middleware/languages","stargazers_url":"https://api.github.com/repos/bre7/leaf-error-middleware/stargazers","contributors_url":"https://api.github.com/repos/bre7/leaf-error-middleware/contributors","subscribers_url":"https://api.github.com/repos/bre7/leaf-error-middleware/subscribers","subscription_url":"https://api.github.com/repos/bre7/leaf-error-middleware/subscription","commits_url":"https://api.github.com/repos/bre7/leaf-error-middleware/commits{/sha}","git_commits_url":"https://api.github.com/repos/bre7/leaf-error-middleware/git/commits{/sha}","comments_url":"https://api.github.com/repos/bre7/leaf-error-middleware/comments{/number}","issue_comment_url":"https://api.github.com/repos/bre7/leaf-error-middleware/issues/comments{/number}","contents_url":"https://api.github.com/repos/bre7/leaf-error-middleware/contents/{+path}","compare_url":"https://api.github.com/repos/bre7/leaf-error-middleware/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bre7/leaf-error-middleware/merges","archive_url":"https://api.github.com/repos/bre7/leaf-error-middleware/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bre7/leaf-error-middleware/downloads","issues_url":"https://api.github.com/repos/bre7/leaf-error-middleware/issues{/number}","pulls_url":"https://api.github.com/repos/bre7/leaf-error-middleware/pulls{/number}","milestones_url":"https://api.github.com/repos/bre7/leaf-error-middleware/milestones{/number}","notifications_url":"https://api.github.com/repos/bre7/leaf-error-middleware/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bre7/leaf-error-middleware/labels{/name}","releases_url":"https://api.github.com/repos/bre7/leaf-error-middleware/releases{/id}","deployments_url":"https://api.github.com/repos/bre7/leaf-error-middleware/deployments","created_at":"2018-03-23T19:36:42Z","updated_at":"2018-03-23T19:36:43Z","pushed_at":"2018-03-24T22:00:04Z","git_url":"git://github.com/bre7/leaf-error-middleware.git","ssh_url":"git@github.com:bre7/leaf-error-middleware.git","clone_url":"https://github.com/bre7/leaf-error-middleware.git","svn_url":"https://github.com/bre7/leaf-error-middleware","homepage":null,"size":19,"stargazers_count":0,"watchers_count":0,"language":"Swift","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"brokenhandsio:master","ref":"master","sha":"20cec7954f8779c4d3925a9e483c678306bcde89","user":{"login":"brokenhandsio","id":23179490,"avatar_url":"https://avatars1.githubusercontent.com/u/23179490?v=4","gravatar_id":"","url":"https://api.github.com/users/brokenhandsio","html_url":"https://github.com/brokenhandsio","followers_url":"https://api.github.com/users/brokenhandsio/followers","following_url":"https://api.github.com/users/brokenhandsio/following{/other_user}","gists_url":"https://api.github.com/users/brokenhandsio/gists{/gist_id}","starred_url":"https://api.github.com/users/brokenhandsio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brokenhandsio/subscriptions","organizations_url":"https://api.github.com/users/brokenhandsio/orgs","repos_url":"https://api.github.com/users/brokenhandsio/repos","events_url":"https://api.github.com/users/brokenhandsio/events{/privacy}","received_events_url":"https://api.github.com/users/brokenhandsio/received_events","type":"Organization","site_admin":false},"repo":{"id":104588421,"name":"leaf-error-middleware","full_name":"brokenhandsio/leaf-error-middleware","owner":{"login":"brokenhandsio","id":23179490,"avatar_url":"https://avatars1.githubusercontent.com/u/23179490?v=4","gravatar_id":"","url":"https://api.github.com/users/brokenhandsio","html_url":"https://github.com/brokenhandsio","followers_url":"https://api.github.com/users/brokenhandsio/followers","following_url":"https://api.github.com/users/brokenhandsio/following{/other_user}","gists_url":"https://api.github.com/users/brokenhandsio/gists{/gist_id}","starred_url":"https://api.github.com/users/brokenhandsio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brokenhandsio/subscriptions","organizations_url":"https://api.github.com/users/brokenhandsio/orgs","repos_url":"https://api.github.com/users/brokenhandsio/repos","events_url":"https://api.github.com/users/brokenhandsio/events{/privacy}","received_events_url":"https://api.github.com/users/brokenhandsio/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/brokenhandsio/leaf-error-middleware","description":"Serve up custom 404 and server error pages for your Vapor App","fork":false,"url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware","forks_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/forks","keys_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/keys{/key_id}","collaborators_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/teams","hooks_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/hooks","issue_events_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/issues/events{/number}","events_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/events","assignees_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/assignees{/user}","branches_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/branches{/branch}","tags_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/tags","blobs_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/git/refs{/sha}","trees_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/git/trees{/sha}","statuses_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/statuses/{sha}","languages_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/languages","stargazers_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/stargazers","contributors_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/contributors","subscribers_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/subscribers","subscription_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/subscription","commits_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/commits{/sha}","git_commits_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/git/commits{/sha}","comments_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/comments{/number}","issue_comment_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/issues/comments{/number}","contents_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/contents/{+path}","compare_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/compare/{base}...{head}","merges_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/merges","archive_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/downloads","issues_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/issues{/number}","pulls_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/pulls{/number}","milestones_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/milestones{/number}","notifications_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/labels{/name}","releases_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/releases{/id}","deployments_url":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/deployments","created_at":"2017-09-23T18:05:36Z","updated_at":"2018-03-23T02:31:15Z","pushed_at":"2018-03-24T22:00:05Z","git_url":"git://github.com/brokenhandsio/leaf-error-middleware.git","ssh_url":"git@github.com:brokenhandsio/leaf-error-middleware.git","clone_url":"https://github.com/brokenhandsio/leaf-error-middleware.git","svn_url":"https://github.com/brokenhandsio/leaf-error-middleware","homepage":null,"size":18,"stargazers_count":13,"watchers_count":13,"language":"Swift","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"archived":false,"open_issues_count":2,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":2,"open_issues":2,"watchers":13,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/pulls/4"},"html":{"href":"https://github.com/brokenhandsio/leaf-error-middleware/pull/4"},"issue":{"href":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/issues/4"},"comments":{"href":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/issues/4/comments"},"review_comments":{"href":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/pulls/4/comments"},"review_comment":{"href":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/pulls/4/commits"},"statuses":{"href":"https://api.github.com/repos/brokenhandsio/leaf-error-middleware/statuses/31b18471ae421215addee5a57adc4efb238eff23"}},"author_association":"NONE"}}
{"actor":{"display_login":"0xTim"}}