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 would look like if these are 40x errors or 50x errors. How do I handle these? What should I expect, say, if the storage has run out on the server? Previously we used to get a 507 error (as in integer), what should I now expect?
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.Explorer | 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-DBDropbox 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,915 PostsLatest Activity: 15 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!