{"action":"created","issue":{"url":"https://api.github.com/repos/Moya/Moya/issues/738","repository_url":"https://api.github.com/repos/Moya/Moya","labels_url":"https://api.github.com/repos/Moya/Moya/issues/738/labels{/name}","comments_url":"https://api.github.com/repos/Moya/Moya/issues/738/comments","events_url":"https://api.github.com/repos/Moya/Moya/issues/738/events","html_url":"https://github.com/Moya/Moya/issues/738","id":184779421,"number":738,"title":"Someone can help me to o add error handling code manually to every request in latest rx version?","user":{"login":"ohohco","id":7972516,"avatar_url":"https://avatars.githubusercontent.com/u/7972516?v=3","gravatar_id":"","url":"https://api.github.com/users/ohohco","html_url":"https://github.com/ohohco","followers_url":"https://api.github.com/users/ohohco/followers","following_url":"https://api.github.com/users/ohohco/following{/other_user}","gists_url":"https://api.github.com/users/ohohco/gists{/gist_id}","starred_url":"https://api.github.com/users/ohohco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ohohco/subscriptions","organizations_url":"https://api.github.com/users/ohohco/orgs","repos_url":"https://api.github.com/users/ohohco/repos","events_url":"https://api.github.com/users/ohohco/events{/privacy}","received_events_url":"https://api.github.com/users/ohohco/received_events","type":"User","site_admin":false},"labels":[{"id":122272862,"url":"https://api.github.com/repos/Moya/Moya/labels/question","name":"question","color":"cc317c","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-10-24T08:34:05Z","updated_at":"2016-12-01T06:09:51Z","closed_at":"2016-12-01T06:09:51Z","body":"Sometimes you don't want to add error handling code manually to every\nrequest. Here is extension for `Observable` to add simple error handling:\n\n``` swift\nextension Observable {\n    func showErrorHUD() -> Observable<Element> {\n        return self.doOn { event in\n            switch event {\n            case .error(let e):\n                // Unwrap underlying error\n                guard let error = e as? Moya.Error else { throw e }\n                guard case .statusCode(let response) = error else { throw e }\n\n                // Check statusCode and handle desired errors\n                if response.statusCode == 401 {\n                    SVProgressHUD.showErrorWithStatus(\"Please log in again\")\n\n                    UserInfo.sharedInstance.invalidate()\n                    Router.sharedInstance.popToLoginScreen()\n                } else {\n                    SVProgressHUD.showErrorWithStatus(\"Error \\(response.statusCode)\")\n                }\n\n            default: break\n            }\n        }\n    }\n}\n```\n\nAbove is older, how to use in the latest version\n"},"comment":{"url":"https://api.github.com/repos/Moya/Moya/issues/comments/264087353","html_url":"https://github.com/Moya/Moya/issues/738#issuecomment-264087353","issue_url":"https://api.github.com/repos/Moya/Moya/issues/738","id":264087353,"user":{"login":"BasThomas","id":4190298,"avatar_url":"https://avatars.githubusercontent.com/u/4190298?v=3","gravatar_id":"","url":"https://api.github.com/users/BasThomas","html_url":"https://github.com/BasThomas","followers_url":"https://api.github.com/users/BasThomas/followers","following_url":"https://api.github.com/users/BasThomas/following{/other_user}","gists_url":"https://api.github.com/users/BasThomas/gists{/gist_id}","starred_url":"https://api.github.com/users/BasThomas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BasThomas/subscriptions","organizations_url":"https://api.github.com/users/BasThomas/orgs","repos_url":"https://api.github.com/users/BasThomas/repos","events_url":"https://api.github.com/users/BasThomas/events{/privacy}","received_events_url":"https://api.github.com/users/BasThomas/received_events","type":"User","site_admin":false},"created_at":"2016-12-01T06:09:51Z","updated_at":"2016-12-01T06:09:51Z","body":"Closing this for now, feel free to reopen when you are still running into this issue!"}}
{"actor":{"display_login":"BasThomas"}}