Select to view content in your preferred language

Downloading preplanned map areas does not refresh tokens

669
2
01-31-2019 03:16 PM
BrendaParker
Emerging Contributor

We've encountered a few scenarios where the runtime (100.4) doesn't try to refresh an expired token for secured resources.  The most recent one we've worked around is DownloadPreplannedOfflineMap from the DownloadPreplannedOfflineMapJob.  It seems that the download doesn't try to refresh an expired token if the call returns a 498 status code.

Shortened stacktrace (removed our callstack):

System.Net.Http.HttpRequestException: Response status code does not indicate success: 498 ().
   at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at Esri.ArcGISRuntime.Internal.RequestRequiredHandler.<IssueRequestAndRespond>d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
We've seen this exception occur in other offline scenarios but have since added other calls through the runtime that have alleviated the issue.
I have seen that the runtime does react to a 401 status code and the 498 is put in the response content, whereas in this issue's case the status code returned is 498.
Is there any way to get the runtime to react appropriately to the 498 when it is returned as a status code so that it will try to refresh the token?  I'd like to be able to write a fix that encompasses the whole project rather than having to test every call to see if it will or will not refresh tokens.
0 Kudos
2 Replies
JenniferNery
Esri Regular Contributor

Can you share some code snippet on how you are handling authentication challenge or adding credentials? At what stage in your app do you get error code 498 (invalid token)? The default client handler we use checks for requests with invalid token and if a token credential is available for the request, it will refresh the token. 

You can use ArcGISHttpClientHandler.HttpRequestBegin to find out which request is failing or if you have already set challenge handler Authentication.Current.ChallengeHandler = new ChallengeHandler ((info) =>{ // you can check here });

Thanks.

0 Kudos
BrendaParker
Emerging Contributor

I am unable to get you the exact request that fails or a code snippet at this time as I am currently working on another project but I can tell you it is the very first request DownloadPreplannedOfflineMap makes once started (a /data endpoint if I recall correctly).

We have a challenge handler set but it doesn't get called at all when this happens.  The request/download task simply fails with a 498 HttpRequestException.

We get the 498 after we start DownloadPreplannedOfflineMap.  By the time we get to this point, other code has already run that is using security successfully.  But if the download is started after the token expires (if the app was sitting open for a while) we get the 498.  If we do pretty much anything else, like re-create the preplanned map area object before we download, that will successfully refresh the token.  Sometimes the refresh happens transparently by the runtime, sometimes it uses our configured challenge handler (we haven't figured out what the determining factor is that chooses which to use) and the download will occur successfully if tried after.

0 Kudos