cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Catching invalid access token exceptions

Catching invalid access token exceptions

Robert S.138
Helpful | Level 7

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

Greg-DB
Dropbox Staff

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! 

Robert S.138
Helpful | Level 7

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.

 

Greg-DB
Dropbox Staff

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.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    Robert S.138 Helpful | Level 7
What do Dropbox user levels mean?