You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.
Forum Discussion
Fahad G.
8 years agoExplorer | Level 4
Java: How do handle 404 and 50x errors?
I'm migrating from V1 to V2. In the past I an error code was an integer that I could look at. Now it's part of a string I presume (i.e. getMessage()). There are no examples of how the errors ...
- 8 years ago
Hi Fahad, if you're using the Dropbox API v2 Java SDK, the SDK will translate these 4xx or 5xx error responses into exceptions for you, so you don't have to parse them yourself.
For instance, in the upload_file example here, there's some basic exception handling for some of the different kinds of exceptions that may get thrown.
The uploadAndFinish method throws a few different types of exceptions. For example, DbxApiException covers some 4xx issues, and DbxException covers some other more general errors.
That way, you don't need to know the specific error codes. You can check the type of the error for more granular error handling. For example, UploadErrorException is a subtype of DbxApiException, and covers some errors specific to uploading. (This would be a 409 from that endpoint.) Likewise, ServerException is a subtype of DbxException, and would indicate a server error. (That would be a 500.)
You can continue checking nested errors for more and more specific information, such as via WriteError.isInsufficientSpace.
Hope this helps!
Fahad G.
8 years agoExplorer | Level 4
In the file DbxRequestUtil.java, method parseErrorBody, I can see that statusCode is not used / appended to the body of the error message. This does not help as we need to be able to handle these errors reliably. What makes it more difficult is that unless you specify the locale to be 'en', all messages are localized, effectively rendering our parsing routines useless.
What I need to do is reliably parse and handle error codes. There's certain part of our app's logic that needs to be triggered, and not just an error displayed. How can I reliably do this with v2?
- Greg-DB8 years agoDropbox Staff
Hi Fahad, if you're using the Dropbox API v2 Java SDK, the SDK will translate these 4xx or 5xx error responses into exceptions for you, so you don't have to parse them yourself.
For instance, in the upload_file example here, there's some basic exception handling for some of the different kinds of exceptions that may get thrown.
The uploadAndFinish method throws a few different types of exceptions. For example, DbxApiException covers some 4xx issues, and DbxException covers some other more general errors.
That way, you don't need to know the specific error codes. You can check the type of the error for more granular error handling. For example, UploadErrorException is a subtype of DbxApiException, and covers some errors specific to uploading. (This would be a 409 from that endpoint.) Likewise, ServerException is a subtype of DbxException, and would indicate a server error. (That would be a 500.)
You can continue checking nested errors for more and more specific information, such as via WriteError.isInsufficientSpace.
Hope this helps!
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,883 PostsLatest Activity: 10 hours agoIf 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!