aaronksaunders / ti_stackmob_new

Other
6 stars 1 forks source link

Integrate the on error retry code that is included in the original stackmob code #4

Open aaronksaunders opened 11 years ago

aaronksaunders commented 11 years ago

in the error handler for the original stackmob code, there appears to be some code that handles error checking

    // Set delay for the next retry attempt
    _.delay(function() {
      var authHeader = getAuthHeader(params);
      params['headers']['Authorization'] = authHeader;
      if (ajaxFunc) ajaxFunc(params);
    }, wait);

In the current implementation of the library, I have set ajaxFunc to null so this code is ignored... but it needs to be changed

ericktai commented 11 years ago

This delay is for StackMob custom code calls.

StackMob server side custom code is spun down if it's not in use. The first request to custom code will result in an error saying that it's starting up. Our SDKs hence have rebuilt try-again logic to automatically retry your custom code call (i think 3 times) before officially calling the error callback. Custom code starts up relatively quickly though, so it's more likely that the subsequent requests will succeed.

On a totally separate note, another instance of the SDKs doing some magic retries behind the scenes is when an access token is past its expiration time. We save the access token expire time locally, so we know when/if a call is going to fail. We put a hold on the params, make a refreshToken call instead, and then on success, we take the original params and make the call. In short, we auto relogin the user behind the scenes and continue their call as expected. If the refresh token request fails, then we go ahead and call the original call's error calblack, which will say "401 unauthorized" (not logged in) or something of the like.

Erick