{"action":"created","issue":{"url":"https://api.github.com/repos/Alamofire/Alamofire/issues/664","labels_url":"https://api.github.com/repos/Alamofire/Alamofire/issues/664/labels{/name}","comments_url":"https://api.github.com/repos/Alamofire/Alamofire/issues/664/comments","events_url":"https://api.github.com/repos/Alamofire/Alamofire/issues/664/events","html_url":"https://github.com/Alamofire/Alamofire/issues/664","id":99966563,"number":664,"title":"Add statusCode to Error in Result enum","user":{"login":"tkrajacic","id":873717,"avatar_url":"https://avatars.githubusercontent.com/u/873717?v=3","gravatar_id":"","url":"https://api.github.com/users/tkrajacic","html_url":"https://github.com/tkrajacic","followers_url":"https://api.github.com/users/tkrajacic/followers","following_url":"https://api.github.com/users/tkrajacic/following{/other_user}","gists_url":"https://api.github.com/users/tkrajacic/gists{/gist_id}","starred_url":"https://api.github.com/users/tkrajacic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tkrajacic/subscriptions","organizations_url":"https://api.github.com/users/tkrajacic/orgs","repos_url":"https://api.github.com/users/tkrajacic/repos","events_url":"https://api.github.com/users/tkrajacic/events{/privacy}","received_events_url":"https://api.github.com/users/tkrajacic/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-08-10T04:08:55Z","updated_at":"2015-08-10T15:11:02Z","closed_at":"2015-08-10T15:11:02Z","body":"While the new Result Type is wonderful, I encountered the following problem with the Error case:\r\n\r\nWhen the Result is passed around, at the place where it is handled, there is no way to get the HTTP status code from a possible Error case. In my case I want to handle an \"Unauthorized\" response with running an authentication request and then re-running the previous request. The method therefore looks if the result was an Error and then would need to check if the actual response code was a 401.\r\n\r\nWould it make sense to add the actual status code to the error? For now there is only the entire message like `Error Domain=com.alamofire.error Code=-6003 \"Response status code was unacceptable: 401\"`"},"comment":{"url":"https://api.github.com/repos/Alamofire/Alamofire/issues/comments/129486214","html_url":"https://github.com/Alamofire/Alamofire/issues/664#issuecomment-129486214","issue_url":"https://api.github.com/repos/Alamofire/Alamofire/issues/664","id":129486214,"user":{"login":"cnoon","id":169110,"avatar_url":"https://avatars.githubusercontent.com/u/169110?v=3","gravatar_id":"","url":"https://api.github.com/users/cnoon","html_url":"https://github.com/cnoon","followers_url":"https://api.github.com/users/cnoon/followers","following_url":"https://api.github.com/users/cnoon/following{/other_user}","gists_url":"https://api.github.com/users/cnoon/gists{/gist_id}","starred_url":"https://api.github.com/users/cnoon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cnoon/subscriptions","organizations_url":"https://api.github.com/users/cnoon/orgs","repos_url":"https://api.github.com/users/cnoon/repos","events_url":"https://api.github.com/users/cnoon/events{/privacy}","received_events_url":"https://api.github.com/users/cnoon/received_events","type":"User","site_admin":false},"created_at":"2015-08-10T15:11:02Z","updated_at":"2015-08-10T15:11:02Z","body":"Anywhere where the `Result` is available, the `NSHTTPURLResponse` is also provided. Therefore, if you are not passing the `response` around where you may need it, that is an implementation problem on the client side, not an issue with Alamofire. This is exactly why it was designed the way it was. \r\n\r\nThere are MANY other things in the `response` that may be useful besides the `statusCode`. Therefore we don't want to make a special exception to the `statusCode`. Here's a quick example of how you should attempt to handle this issue.\r\n\r\n```swift\r\nAlamofire.request(.GET, \"https://httpbin.org/get\")\r\n    .responseJSON { request, response, result in\r\n        switch result {\r\n        case .Success(let JSON):\r\n            print(JSON)\r\n        case .Failure(let data, let error):\r\n            print(response?.statusCode)\r\n            print(error)\r\n\r\n            callFailureMethod(response: response, result: result)\r\n        }\r\n    }\r\n```\r\n\r\nor\r\n\r\n```swift\r\nAlamofire.request(.GET, \"https://httpbin.org/get\")\r\n    .responseJSON { request, response, result in\r\n        debugPrint(result)\r\n        print(response?.statusCode)\r\n\r\n        callFailureMethod(response: response, result: result)\r\n    }\r\n```\r\n\r\nBest of luck!"}}