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
Keith B.7
9 years agoHelpful | Level 7
Objective-C API 2 - dealing with error codes
Hello, In transitioning my API 1 Obj-C code over to API 2, I'm slightly confused over how to deal with certain error codes in API 2 - or even how to locate them properly. # 1. Create Folder E...
- 9 years ago
I see, if you're looking for that case in particular, in API v2 lock contention is now a 429 with a structured too_many_write_operations error. In the SDK that should be a DBAUTHRateLimitError with a TooManyWriteOperations DBAUTHRateLimitReason.
Greg-DB
9 years agoDropbox Staff
Hi Keith,
1. What you have already is the right way to start this, but you can continue drilling down into the error object, e.g.:
[[client.filesRoutes createFolder:@"/test/path"] response:^(DBFILESFolderMetadata *result, DBFILESCreateFolderError *routeError, DBError *error) { if (result) { NSLog(@"%@\n", result); } else if (routeError) { NSLog(@"%@\n", routeError); if ([routeError isPath]) { if ([routeError.path isConflict]) { if ([routeError.path.conflict isFolder]) { NSLog(@"Could not create folder because a folder already exists at path."); } } } // and so on for other errors } else if (error) { NSLog(@"%@\n", error); } }];
You can make your error handling as general or specific as you like this way.
2. Similarly, you can check the specific error returned to see if a delete call failed because nothing was found at the path, e.g.:
[[client.filesRoutes delete_:@"/test/path"] response:^(DBFILESMetadata *result, DBFILESDeleteError *routeError, DBError *error) { if (result) { NSLog(@"%@\n", result); } else if (routeError) { NSLog(@"%@\n", routeError); if ([routeError isPathLookup]) { if ([routeError.pathLookup isNotFound]) { NSLog(@"Nothing found at path."); } // and so on for other errors } } else if (error) { NSLog(@"%@\n", error); } }];
3. Yes, you can just use one or the other.
4. When using the SDK, you don't really need to worry about the actual HTTP error codes, as the SDK translates everything into objects and errors for you, like in the sample snippets above. For higher level errors, there's a good example here.
5. Attempting to upload to an over quota account will result in an route-specific insufficient space error. E.g., in the SDK that would look like:
[[client.filesRoutes uploadData:@"/test/path" inputData:fileData] response:^(DBFILESFileMetadata *result, DBFILESUploadError *routeError, DBError *error) { if (result) { NSLog(@"%@\n", result); } else if (routeError) { NSLog(@"%@\n", routeError); if ([routeError isPath]) { if ([routeError.path.reason isInsufficientSpace]) { NSLog(@"Could not upload because the account is over quota."); } // and so on for other errors } } else if (error) { NSLog(@"%@\n", error); } }];
Hope this helps!
- Keith B.79 years agoHelpful | Level 7
That helps lots, thank you! I think I'm nearly there... One question on (4):
What about for errors that aren't covered in the framework. For instance, if you recall, I found that I was encountering random 503 "failed to grab file lock" errors, in which case I would use the "retry-after" header. In API 2, the status code for this is 429. In this instance, I assume I still use the DBError's status code to check for this? Or is the "failed to grab file locks" error always the same as a rate limit error? Are you saying I should never need to call the statusCode property?
Thanks again,
Keith
- Greg-DB9 years agoDropbox Staff
I don't believe there's any case where you necessarily need to check the status code directly. The translation is here if you're interested, but a 503 will yield a DBRequestErrorInternalServer and a 429 will yield a DBRequestErrorRateLimit, so you don't need to access the statusCode directly for either of those. Further, anything not specifically covered there will be a DBRequestErrorHttp.
- Keith B.79 years agoHelpful | Level 7
Great, thank you! With regard to a 503, though, a DBRequestErrorInternalServer is just a generic "anything over 500" error, isn't it? So if I want to check specifically for a file lock error, is it safe still to check for the 503 error? (That is, will DBError report a status code of 503 in this case?)
All the best,
Keith
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,915 PostsLatest Activity: 2 days 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!