{"action":"created","comment":{"url":"https://api.github.com/repos/Rentlio/SwiftRestModel/pulls/comments/59257795","id":59257795,"diff_hunk":"@@ -123,19 +123,23 @@ public class SwiftRestModel: NSObject\n         }\n         \n         Alamofire.request(requestMethod, url, parameters: parameters, headers: headers, encoding: encoding)\n+            .validate()\n             .responseJSON { response in\n-                if response.result.isSuccess {\n+                switch response.result {\n+                case .Success:\n                     let json = JSON(data: response.data!)\n                     self.data = json\n                     self.parse()\n                     if success != nil {\n                         success!(response: json)\n                     }\n-                } else {\n-                    let json: JSON = [\"error\": (response.result.error?.userInfo[\"NSLocalizedDescription\"])!]\n-                    if error != nil {\n-                        error!(response: json)\n+                case .Failure(let responseError):\n+                    var json = JSON([\"error\": responseError.localizedDescription])\n+                    if let responseStatus = response.response?.statusCode {\n+                        json[\"status\"] = JSON(responseStatus)\n                     }\n+\n+                    error!(response: json)","path":"Source/SwiftRestModel.swift","position":null,"original_position":25,"commit_id":"bc48ed863dc17ec2f3999d0bff1a9681700bfea9","original_commit_id":"06c8249c5b11d61b3416081100e46f11f1e3f7f7","user":{"login":"dominic","id":185645,"avatar_url":"https://avatars.githubusercontent.com/u/185645?v=3","gravatar_id":"","url":"https://api.github.com/users/dominic","html_url":"https://github.com/dominic","followers_url":"https://api.github.com/users/dominic/followers","following_url":"https://api.github.com/users/dominic/following{/other_user}","gists_url":"https://api.github.com/users/dominic/gists{/gist_id}","starred_url":"https://api.github.com/users/dominic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dominic/subscriptions","organizations_url":"https://api.github.com/users/dominic/orgs","repos_url":"https://api.github.com/users/dominic/repos","events_url":"https://api.github.com/users/dominic/events{/privacy}","received_events_url":"https://api.github.com/users/dominic/received_events","type":"User","site_admin":false},"body":"Oops, sorry. I lost your `nil` check there - restored.","created_at":"2016-04-11T18:39:33Z","updated_at":"2016-04-11T18:39:33Z","html_url":"https://github.com/Rentlio/SwiftRestModel/pull/7#discussion_r59257795","pull_request_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/pulls/7","_links":{"self":{"href":"https://api.github.com/repos/Rentlio/SwiftRestModel/pulls/comments/59257795"},"html":{"href":"https://github.com/Rentlio/SwiftRestModel/pull/7#discussion_r59257795"},"pull_request":{"href":"https://api.github.com/repos/Rentlio/SwiftRestModel/pulls/7"}}},"pull_request":{"url":"https://api.github.com/repos/Rentlio/SwiftRestModel/pulls/7","id":63969270,"html_url":"https://github.com/Rentlio/SwiftRestModel/pull/7","diff_url":"https://github.com/Rentlio/SwiftRestModel/pull/7.diff","patch_url":"https://github.com/Rentlio/SwiftRestModel/pull/7.patch","issue_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/issues/7","number":7,"state":"open","locked":false,"title":"Handle errors for responses outside successful status codes","user":{"login":"dominic","id":185645,"avatar_url":"https://avatars.githubusercontent.com/u/185645?v=3","gravatar_id":"","url":"https://api.github.com/users/dominic","html_url":"https://github.com/dominic","followers_url":"https://api.github.com/users/dominic/followers","following_url":"https://api.github.com/users/dominic/following{/other_user}","gists_url":"https://api.github.com/users/dominic/gists{/gist_id}","starred_url":"https://api.github.com/users/dominic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dominic/subscriptions","organizations_url":"https://api.github.com/users/dominic/orgs","repos_url":"https://api.github.com/users/dominic/repos","events_url":"https://api.github.com/users/dominic/events{/privacy}","received_events_url":"https://api.github.com/users/dominic/received_events","type":"User","site_admin":false},"body":"The request method now includes a call to `.validate()`, faulting to the failure block for any response outside the 200..299 range. In the request handler, we now switch on the response type, and pass through a JSON error that includes a response status code when available.\r\n\r\nPreviously, the failure handler would throw a bad access exception at [this line](https://github.com/Rentlio/SwiftRestModel/blob/master/Source/SwiftRestModel.swift#L135) by forcefully unwrapping the `userInfo[\"NSLocalizedDescription\"]`. This uses the Alamofire `Result` enum's `Failure` value to safely access the objects localized description.","created_at":"2016-03-23T23:29:33Z","updated_at":"2016-04-11T18:39:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"32c6b48340e36ae6f00d099d5b54daf215ab395d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/pulls/7/commits","review_comments_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/pulls/7/comments","review_comment_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/issues/7/comments","statuses_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/statuses/bc48ed863dc17ec2f3999d0bff1a9681700bfea9","head":{"label":"dominic:validate-errors","ref":"validate-errors","sha":"bc48ed863dc17ec2f3999d0bff1a9681700bfea9","user":{"login":"dominic","id":185645,"avatar_url":"https://avatars.githubusercontent.com/u/185645?v=3","gravatar_id":"","url":"https://api.github.com/users/dominic","html_url":"https://github.com/dominic","followers_url":"https://api.github.com/users/dominic/followers","following_url":"https://api.github.com/users/dominic/following{/other_user}","gists_url":"https://api.github.com/users/dominic/gists{/gist_id}","starred_url":"https://api.github.com/users/dominic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dominic/subscriptions","organizations_url":"https://api.github.com/users/dominic/orgs","repos_url":"https://api.github.com/users/dominic/repos","events_url":"https://api.github.com/users/dominic/events{/privacy}","received_events_url":"https://api.github.com/users/dominic/received_events","type":"User","site_admin":false},"repo":{"id":54595609,"name":"SwiftRestModel","full_name":"dominic/SwiftRestModel","owner":{"login":"dominic","id":185645,"avatar_url":"https://avatars.githubusercontent.com/u/185645?v=3","gravatar_id":"","url":"https://api.github.com/users/dominic","html_url":"https://github.com/dominic","followers_url":"https://api.github.com/users/dominic/followers","following_url":"https://api.github.com/users/dominic/following{/other_user}","gists_url":"https://api.github.com/users/dominic/gists{/gist_id}","starred_url":"https://api.github.com/users/dominic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dominic/subscriptions","organizations_url":"https://api.github.com/users/dominic/orgs","repos_url":"https://api.github.com/users/dominic/repos","events_url":"https://api.github.com/users/dominic/events{/privacy}","received_events_url":"https://api.github.com/users/dominic/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dominic/SwiftRestModel","description":"Swift helper for REST models","fork":true,"url":"https://api.github.com/repos/dominic/SwiftRestModel","forks_url":"https://api.github.com/repos/dominic/SwiftRestModel/forks","keys_url":"https://api.github.com/repos/dominic/SwiftRestModel/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dominic/SwiftRestModel/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dominic/SwiftRestModel/teams","hooks_url":"https://api.github.com/repos/dominic/SwiftRestModel/hooks","issue_events_url":"https://api.github.com/repos/dominic/SwiftRestModel/issues/events{/number}","events_url":"https://api.github.com/repos/dominic/SwiftRestModel/events","assignees_url":"https://api.github.com/repos/dominic/SwiftRestModel/assignees{/user}","branches_url":"https://api.github.com/repos/dominic/SwiftRestModel/branches{/branch}","tags_url":"https://api.github.com/repos/dominic/SwiftRestModel/tags","blobs_url":"https://api.github.com/repos/dominic/SwiftRestModel/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dominic/SwiftRestModel/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dominic/SwiftRestModel/git/refs{/sha}","trees_url":"https://api.github.com/repos/dominic/SwiftRestModel/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dominic/SwiftRestModel/statuses/{sha}","languages_url":"https://api.github.com/repos/dominic/SwiftRestModel/languages","stargazers_url":"https://api.github.com/repos/dominic/SwiftRestModel/stargazers","contributors_url":"https://api.github.com/repos/dominic/SwiftRestModel/contributors","subscribers_url":"https://api.github.com/repos/dominic/SwiftRestModel/subscribers","subscription_url":"https://api.github.com/repos/dominic/SwiftRestModel/subscription","commits_url":"https://api.github.com/repos/dominic/SwiftRestModel/commits{/sha}","git_commits_url":"https://api.github.com/repos/dominic/SwiftRestModel/git/commits{/sha}","comments_url":"https://api.github.com/repos/dominic/SwiftRestModel/comments{/number}","issue_comment_url":"https://api.github.com/repos/dominic/SwiftRestModel/issues/comments{/number}","contents_url":"https://api.github.com/repos/dominic/SwiftRestModel/contents/{+path}","compare_url":"https://api.github.com/repos/dominic/SwiftRestModel/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dominic/SwiftRestModel/merges","archive_url":"https://api.github.com/repos/dominic/SwiftRestModel/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dominic/SwiftRestModel/downloads","issues_url":"https://api.github.com/repos/dominic/SwiftRestModel/issues{/number}","pulls_url":"https://api.github.com/repos/dominic/SwiftRestModel/pulls{/number}","milestones_url":"https://api.github.com/repos/dominic/SwiftRestModel/milestones{/number}","notifications_url":"https://api.github.com/repos/dominic/SwiftRestModel/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dominic/SwiftRestModel/labels{/name}","releases_url":"https://api.github.com/repos/dominic/SwiftRestModel/releases{/id}","deployments_url":"https://api.github.com/repos/dominic/SwiftRestModel/deployments","created_at":"2016-03-23T21:54:00Z","updated_at":"2016-03-23T21:54:00Z","pushed_at":"2016-04-11T18:39:25Z","git_url":"git://github.com/dominic/SwiftRestModel.git","ssh_url":"git@github.com:dominic/SwiftRestModel.git","clone_url":"https://github.com/dominic/SwiftRestModel.git","svn_url":"https://github.com/dominic/SwiftRestModel","homepage":null,"size":42,"stargazers_count":0,"watchers_count":0,"language":"Swift","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"Rentlio:master","ref":"master","sha":"7f91bc9fb031d827d568d72431ac0bc28e93c1f4","user":{"login":"Rentlio","id":14963689,"avatar_url":"https://avatars.githubusercontent.com/u/14963689?v=3","gravatar_id":"","url":"https://api.github.com/users/Rentlio","html_url":"https://github.com/Rentlio","followers_url":"https://api.github.com/users/Rentlio/followers","following_url":"https://api.github.com/users/Rentlio/following{/other_user}","gists_url":"https://api.github.com/users/Rentlio/gists{/gist_id}","starred_url":"https://api.github.com/users/Rentlio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Rentlio/subscriptions","organizations_url":"https://api.github.com/users/Rentlio/orgs","repos_url":"https://api.github.com/users/Rentlio/repos","events_url":"https://api.github.com/users/Rentlio/events{/privacy}","received_events_url":"https://api.github.com/users/Rentlio/received_events","type":"Organization","site_admin":false},"repo":{"id":50566525,"name":"SwiftRestModel","full_name":"Rentlio/SwiftRestModel","owner":{"login":"Rentlio","id":14963689,"avatar_url":"https://avatars.githubusercontent.com/u/14963689?v=3","gravatar_id":"","url":"https://api.github.com/users/Rentlio","html_url":"https://github.com/Rentlio","followers_url":"https://api.github.com/users/Rentlio/followers","following_url":"https://api.github.com/users/Rentlio/following{/other_user}","gists_url":"https://api.github.com/users/Rentlio/gists{/gist_id}","starred_url":"https://api.github.com/users/Rentlio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Rentlio/subscriptions","organizations_url":"https://api.github.com/users/Rentlio/orgs","repos_url":"https://api.github.com/users/Rentlio/repos","events_url":"https://api.github.com/users/Rentlio/events{/privacy}","received_events_url":"https://api.github.com/users/Rentlio/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Rentlio/SwiftRestModel","description":"Swift helper for REST models","fork":false,"url":"https://api.github.com/repos/Rentlio/SwiftRestModel","forks_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/forks","keys_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/teams","hooks_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/hooks","issue_events_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/issues/events{/number}","events_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/events","assignees_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/assignees{/user}","branches_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/branches{/branch}","tags_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/tags","blobs_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/git/refs{/sha}","trees_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/statuses/{sha}","languages_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/languages","stargazers_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/stargazers","contributors_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/contributors","subscribers_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/subscribers","subscription_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/subscription","commits_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/commits{/sha}","git_commits_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/git/commits{/sha}","comments_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/comments{/number}","issue_comment_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/issues/comments{/number}","contents_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/contents/{+path}","compare_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/merges","archive_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/downloads","issues_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/issues{/number}","pulls_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/pulls{/number}","milestones_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/milestones{/number}","notifications_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/labels{/name}","releases_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/releases{/id}","deployments_url":"https://api.github.com/repos/Rentlio/SwiftRestModel/deployments","created_at":"2016-01-28T07:59:34Z","updated_at":"2016-03-12T17:26:10Z","pushed_at":"2016-04-11T18:39:26Z","git_url":"git://github.com/Rentlio/SwiftRestModel.git","ssh_url":"git@github.com:Rentlio/SwiftRestModel.git","clone_url":"https://github.com/Rentlio/SwiftRestModel.git","svn_url":"https://github.com/Rentlio/SwiftRestModel","homepage":null,"size":47,"stargazers_count":7,"watchers_count":7,"language":"Swift","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":2,"forks":2,"open_issues":2,"watchers":7,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Rentlio/SwiftRestModel/pulls/7"},"html":{"href":"https://github.com/Rentlio/SwiftRestModel/pull/7"},"issue":{"href":"https://api.github.com/repos/Rentlio/SwiftRestModel/issues/7"},"comments":{"href":"https://api.github.com/repos/Rentlio/SwiftRestModel/issues/7/comments"},"review_comments":{"href":"https://api.github.com/repos/Rentlio/SwiftRestModel/pulls/7/comments"},"review_comment":{"href":"https://api.github.com/repos/Rentlio/SwiftRestModel/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Rentlio/SwiftRestModel/pulls/7/commits"},"statuses":{"href":"https://api.github.com/repos/Rentlio/SwiftRestModel/statuses/bc48ed863dc17ec2f3999d0bff1a9681700bfea9"}}}}