cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements
Update: Find information on Dropbox support during COVID-19 here
Close
cancel
Showing results for 
Search instead for 
Did you mean: 

Catching invalid access token exceptions

Robert S.138
Explorer | Level 3

In the Android Core API v2 SDK, when a Dropbox access token becomes invalid, I want to catch that exception and null out my copy of the access token so the linking authorization will be done again.  The trouble is, I don't know how to exactly qualify that particular exception.  For testing purposes I have deliberately fed the wrong access token to the API (rather than invalidate the actual token with Dropbox).  For me, the exception happens on listFolder().  And the exception thrown is the DbxException.  Buy why isn't it the InvalidAccessTokenException?  Apparently that is a real thing, a subclass of DbxException.  But it does not check with:

  if(e instanceof InvalidAccessTokenException)

but only with:

  if(e instanceof DbxException)

If there are any other reasons for any of these API functions to throw a DbxException besides an invalid access token, it would be wrong for me to pretend that the access token is the only problem.  So I would like to detect when this specific exception is thrown, as distinct from all others.

3 Replies 3

Re: Catching invalid access token exceptions

Dropboxer
Dropboxer

InvalidAccessTokenException does get thrown for me when calling listFolder with an invalid access token. (Both catching InvalidAccessTokenException and using instanceof work as expected in my test.)

Can you share your code that reproduces this? What version of the SDK do you have installed?

Also, please print and share the stack trace for the exception you do get. Thanks in advance! 

Re: Catching invalid access token exceptions

Robert S.138
Explorer | Level 3

Maybe it is the way I faked the invalid token.  Instead of passing a real, but invalidated token, I passed

   "Z" + validToken

to the "new DbxClientV2(requestConfig, DBaccessToken);" API call.  So it has one more letter than the real token.  And the message with that exception is "OAuth2 token is mal-formed".  I'll bet that's it.

 

Re: Catching invalid access token exceptions

Dropboxer
Dropboxer

Yes, that would do it. That gives you that BadRequestException instead, since the token is recognizably not the right format. If instead you just modify an existing character in the access token in place you can force the InvalidAccessTokenException instead.

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?