cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
We've been busy working on some major updates to the Community, so check out what's changing, what’s staying the same and what you can expect from the Dropbox Community right 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: 

Java: How do handle 404 and 50x errors?

Java: How do handle 404 and 50x errors?

Fahad G.
Explorer | Level 4
Go to solution

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?

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

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! 

View solution in original post

2 Replies 2

Fahad G.
Explorer | Level 4
Go to solution

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-DB
Dropbox Staff
Go to solution

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! 

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    Fahad G. Explorer | Level 4
What do Dropbox user levels mean?