bean
bean

Reputation: 1101

RestKit - Repeat request if auth timeout

I'm talking to a .NET Web API 2 service, using it's default "Individual User Accounts" authentication. I'm using RestKit 0.22.0.

My issue is that when a session timeout occurs, I want to have the iOS app re-authenticate with the stored credentials and then replay the request. The only way I've found to do this is like this - asked a year ago. However I do not think that the answer should be to check if the status code is 401, re-authenticate, retry the request in every failure block. As that's just a lot of copy and pasting!

Is there a better way to accomplish what I want?

Upvotes: 0

Views: 512

Answers (1)

Wain
Wain

Reputation: 119031

Call a common method from the failure block which takes the required inputs. Preferably you might want to have multiple common methods which are capable of verifying the response details and restarting the process automatically (so 1 for GET, 1 for POST, ...).


Pseudo code

- (void)do something with this info: 
{
    ... calculate method specifics then call general method ...
    [self getObjectsAtPath:urlArg parameters:p success:s];
}

- (void)getObjectsAtPath:urlArg
              parameters:p
                 success:s
{
    [RK getObjectsAtPath:urlArg
              parameters:nil
                 success:
     { -- Yay -- call success callback
       s();
     }
                 failure:
     { -- Humph -- retry
       ... do auth updates, then retry ...
       [self getObjectsAtPath:urlArg parameters:p success:s];
     }
}

Upvotes: 2

Related Questions