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: 

iOS: Detect when DBError is "Invalid Access Token"

Robert S.138
Explorer | Level 3

I need to determine when a DBError instance returned from listFolder: or downloadData: is because of an Invalid Access Token.  So far I can see how to transform the DBError into a DBRequestAuthError using:

[error asAuthError]

provided [error isAuthError].  And I can see how to check for Invalid Access Token in an instance of DBAuthError using [... isInvalidAccessToken].  But I don't know how to get from a DBRequestAuthError to a DBAuthError.  isInvalidAccessToken: does not apply to class DBRequestAuthError.

3 Replies 3

Re: iOS: Detect when DBError is "Invalid Access Token"

Dropboxer
Dropboxer

Hi Robert, it sounds like you're looking for the structuredAuthError property on DBRequestAuthError. That will give you the DBAUTHAuthError, on which you can call isInvalidAccessToken etc. E.g.:

 if (authError.structuredAuthError.isInvalidAccessToken) {
NSLog(@"Invalid acess token.");
}

Hope this helps! 

Re: iOS: Detect when DBError is "Invalid Access Token"

Robert S.138
Explorer | Level 3

Yes, that compiles without errors.  I am doing this:

if( [dbError isAuthError]  ) {
    DBRequestAuthError* dbAuthError = [dbError asAuthError];
    if (dbAuthError.structuredAuthError.isInvalidAccessToken) {
        //..handle Invalid Access Token Error
    }
}

where dbError is the instance of DBError returned by the API. But I am also curious about the need for the method "asAuthError".  Could I not just as well do this:

if( [dbError isAuthError]  ) {
    if (dbError.structuredAuthError.isInvalidAccessToken) {
        //..handle Invalid Access Token Error
    }
}

This also compiles without any errors or warnings.  Will it work?

 

Re: iOS: Detect when DBError is "Invalid Access Token"

Dropboxer
Dropboxer

I believe either way is safe as long as you have that isAuthError check. The asAuthError call just gives you the object as DBRequestAuthError instead of DBRequestHttpError, but it doesn't seem to make a difference in this case.

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?