function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bdPeterbdPeter 

App should retry REST call if fail due to token refresh?

When my app is resumed (as a result of waking up the device after it is not used for a day), the first REST calls fail because apparently (according to the log) a new token must be acquired.

 

As a result my app is catching an exception. Then if the user manually retries (i.e. doing another action in the app that causes a REST SOQL call), everything works fine. The user is not asked to login again. Apparently a refresh token was successfully obtained.

 

See log at https://dl.dropboxusercontent.com/u/40554620/Logs/Resume-with-expired-token.txt for details.

To make sure I understand the responsibilities of the app: is the app expected to retry when the exception is caught or is the SDK responsible for a retry? I go either way; I just need to know whose responsibility it is so I can code it up properly.

 

To avoid (potentially complicated) retry handling all together, is there an option to force the SDK to always refresh the token when the app is resumed? I guess my app could issue some REST call on resume to accomplish this.

 

Thanks

Peter

 

Best Answer chosen by Admin (Salesforce Developers) 
bdPeterbdPeter

In my bootconfig.json I had specified ["api", "refresh_token"] instead of just ["api"] like in the sample apps. After I changed that I did not see the problem anymore.

 

All Answers

bhariharanbhariharan

If you're using forcetk.mobilesdk.js, the first call should intercept the 401 response and replay the request. What version of the Mobile SDK are you on, and are you using forcetk.mobilesdk.js, or a standalone version of forcetk?

bdPeterbdPeter

Thanks, Bharath. I am using the forcetk.mobilesdk.js (v2.0.0) from the 2.0.3 SDK as is without any modifications. The code to initialize the forcetkClient is located in https://dl.dropboxusercontent.com/u/40554620/Logs/forcetk.init.js

 

Peter

bdPeterbdPeter

In my bootconfig.json I had specified ["api", "refresh_token"] instead of just ["api"] like in the sample apps. After I changed that I did not see the problem anymore.

 

This was selected as the best answer