Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request retry support #55

Closed
mayur-gauswami opened this issue Oct 25, 2017 · 3 comments
Closed

Request retry support #55

mayur-gauswami opened this issue Oct 25, 2017 · 3 comments
Assignees
Milestone

Comments

@mayur-gauswami
Copy link

Any roadmap to support request retry scenarios. e.g. retry the request with correct auth header.

@DenTelezhkin
Copy link
Member

I do want to look into Alamofire Request adapters and retriers, but did not have time to do that unfortunately. You may actually be able to use them right now in current TRON release by specifying them directly on Alamofire SessionManager, that you pass into TRON.

Take a look at Alamofire readme on how to do that - specifically retriers and adapters section: https://github.com/Alamofire/Alamofire#requestadapter

I will leave this issue open for now, since we might be adopting those API's in TRON, deprecating HeaderBuildable protocols for example, since they are achieving the same thing.

@mayur-gauswami
Copy link
Author

For now i have used below approach:
As i had tricky use case in which i wanted to retry with different host if request fails which is kind a fallback mechanism for URL:

if http://domain1.com/path/req -> fails try with -> http://domain2.com/path/req

So basically i wanted to recreate request object and retry again. At the same time i wanted to put all these logic encapsulated. So i implemented few changes as below:

open class MyAPIRequest<Model, ErrorModel>: BaseRequest<Model, ErrorModel> {
    .
    .
    var apiRequest: Alamofire.DataRequest?
    .
    .
    open func cancel() {
        apiRequest?.cancel()
    }

    open func perform(withSuccess successBlock: ((Model) -> Void)? = nil,
                                failure failureBlock: ((APIError<ErrorModel>) -> Void)? = nil) 
                                -> Self 
    {
        .
        .
        return self
    }

    private func performAlamofireRequest(_ completion : @escaping (DataResponse<Model>) -> Void) -> Self 
    {
         .
         .
         self.apiRequest = alamofireRequest(from: manager) as? DataRequest
         .
         // custom retry logic
         .
         return self
    }
}

This implementation gives me few controls:

  • Encapsulates Alamofire request objects
  • I can retry the request with different instance which is helpful if any use cases needs request to be mutable. in my case i wanted to change URL property.

@DenTelezhkin DenTelezhkin modified the milestones: 4.1.0, 5.0.0 Dec 27, 2017
@DenTelezhkin
Copy link
Member

Hi! I've implemented support for per-request interceptors on master branch 0043c4e and will be releasing it in next 5.0 beta and of course in final release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants