One month down in 2025: How are your resolutions coming along? Check out how to get back on track here.
Forum Discussion
Graham B.
8 years agoNew member | Level 2
[Java SDK v2] migration: error handling with HTTP codes
I'm migrating to the v2 Java SDK on Android, from the old Android SDK. I'm struggling to convert some error-handling code. This is a high-level error handler which could be handling an exception from any one of a number of Dropbox API methods.
Here's how it used to look:
if (DropboxServerException.class.isInstance(exception)) { switch (((DropboxServerException) exception).error) { case DropboxServerException._401_UNAUTHORIZED: case DropboxServerException._403_FORBIDDEN: case DropboxServerException._404_NOT_FOUND: Log.w(TAG, "data has moved/disappeared, or something equally terminal."); // do some error handling break; }
}
Now it looks as if I'm supposed to examine any one of dozens of different DbxApiException subclasses, and try to extract a meaningful error code from their messages. Please tell me there's a better way?
- Greg-DB
Dropbox Staff
API v2 does offer much more granular errors, but you can use as much or as little of that granularity in your app as you want.
For instance, this example only does high level handling of any DbxException:
Wheres this example distinguishes between CreateSharedLinkWithSettingsErrorException and DbxException:
You can drill down into the subclasses to whatever extent you want for your app. For example, a InvalidAccessTokenException indicates a bad access token, like a 401 in your v1 code.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,945 PostsLatest Activity: 2 hours ago
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!