{"action":"created","issue":{"url":"https://api.github.com/repos/bustoutsolutions/siesta/issues/152","repository_url":"https://api.github.com/repos/bustoutsolutions/siesta","labels_url":"https://api.github.com/repos/bustoutsolutions/siesta/issues/152/labels{/name}","comments_url":"https://api.github.com/repos/bustoutsolutions/siesta/issues/152/comments","events_url":"https://api.github.com/repos/bustoutsolutions/siesta/issues/152/events","html_url":"https://github.com/bustoutsolutions/siesta/issues/152","id":191890485,"number":152,"title":"How to: decorateRequests with callback methods","user":{"login":"Tazer","id":132698,"avatar_url":"https://avatars.githubusercontent.com/u/132698?v=3","gravatar_id":"","url":"https://api.github.com/users/Tazer","html_url":"https://github.com/Tazer","followers_url":"https://api.github.com/users/Tazer/followers","following_url":"https://api.github.com/users/Tazer/following{/other_user}","gists_url":"https://api.github.com/users/Tazer/gists{/gist_id}","starred_url":"https://api.github.com/users/Tazer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tazer/subscriptions","organizations_url":"https://api.github.com/users/Tazer/orgs","repos_url":"https://api.github.com/users/Tazer/repos","events_url":"https://api.github.com/users/Tazer/events{/privacy}","received_events_url":"https://api.github.com/users/Tazer/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-11-27T22:32:02Z","updated_at":"2016-11-30T16:18:07Z","closed_at":null,"body":"Hello,\r\n\r\nI'm trying to implement this example: http://bustoutsolutions.github.io/siesta/guide/configuration/#decorating-requests-via-configuration\r\n\r\nBut getting into trouble , cause I'm getting the new token async, so don't see how I should make that code work. This is how far I have gotten:\r\n\r\n```\r\n    func refreshTokenOnAuthFailure(request: Request) -> Request {\r\n        return request.chained {\r\n            guard case .failure(let error) = $0.response,  // Did request fail…\r\n                error.httpStatusCode == 401 else {           // …because of expired token?\r\n                    return .useThisResponse                    // If not, use the response we got.\r\n            }\r\n            \r\n            \r\n            \r\n            \r\n            if let refreshToken = self.authService.getRefreshToken(){\r\n                self.authService.fetchNewToken(refreshToken:refreshToken).then { token -> Void in\r\n                     //Async stuff , how should I do to retry the request here ? <-- problem here\r\n                    // callback request.repeated()\r\n                    }.catch {error in\r\n                        //also .useThisResponse.\r\n                }\r\n            }\r\n            \r\n            \r\n            \r\n            return .useThisResponse;\r\n        }\r\n    }\r\n```\r\n\r\nSo this code does kinda nothing. I have looked at the closest issues also but don't really see an solution to my problem. \r\n\r\nAnyway that could guide me in the right direction ? :) \r\n\r\nJust a FYI: I'm kinda new to Swift/iOS dev, so maybe I'm missing something obvious."},"comment":{"url":"https://api.github.com/repos/bustoutsolutions/siesta/issues/comments/263917379","html_url":"https://github.com/bustoutsolutions/siesta/issues/152#issuecomment-263917379","issue_url":"https://api.github.com/repos/bustoutsolutions/siesta/issues/152","id":263917379,"user":{"login":"pcantrell","id":378162,"avatar_url":"https://avatars.githubusercontent.com/u/378162?v=3","gravatar_id":"","url":"https://api.github.com/users/pcantrell","html_url":"https://github.com/pcantrell","followers_url":"https://api.github.com/users/pcantrell/followers","following_url":"https://api.github.com/users/pcantrell/following{/other_user}","gists_url":"https://api.github.com/users/pcantrell/gists{/gist_id}","starred_url":"https://api.github.com/users/pcantrell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pcantrell/subscriptions","organizations_url":"https://api.github.com/users/pcantrell/orgs","repos_url":"https://api.github.com/users/pcantrell/repos","events_url":"https://api.github.com/users/pcantrell/events{/privacy}","received_events_url":"https://api.github.com/users/pcantrell/received_events","type":"User","site_admin":false},"created_at":"2016-11-30T16:18:07Z","updated_at":"2016-11-30T16:18:07Z","body":"Yup, then there is an issue to resolve here. Siesta uses `RequestChainAction` instead of more open-ended promises to ensure that chained requests honor the general `Request` contract of having exactly one result.\r\n\r\nThat’s lovely if you’re staying entirely inside the world of Siesta requests, but give you no simple way to wait on something else (such as a PromiseKit promise). It’s possible to do it by writing your own `Request` implementation that wraps a promise, but Siesta ought to provide that escape hatch for you. I’ll leave this issue open for that."}}
{"actor":{"display_login":"pcantrell"}}