We are aware of the issue with the badge emails resending to everyone, we apologise for the inconvenience - learn more here.
Forum Discussion
billymeltdown
9 years agoExplorer | Level 4
Obj-C API v2 Error Handling
Hi folks, I find myself having more questions about error handling in the obj-c API v2. I keep going over the README and I am still unable to figure out where I should look for documentation on figur...
- 9 years ago
For each API call, you'll want to handle both the route error (for errors specific to that call) as well as the general error (for errors that can happen on any call).
For the route specific error for createFolder, which is DBFILESCreateFolderError, there is only the isPath case, since that error doesn't have any other scenarios. (The example in the README is for the delete call, which has a different set of possible route-specific errors, under DBFILESDeleteError.)
To see what is possible for any particular error, I recommend checking the Objective-C SDK documentation for that error type, e.g., DBFILESCreateFolderError, which lists just isPath. (You can look at the HTTP documenation, as you linked to, but the names won't always be exactly the same, as they get translated slightly for the SDK.)
So, if DBFILESCreateFolderError isPath is true, you can then access the DBFILESWriteError in it via the path field.
Here's a more elaborate sample for createFolder showing that:
[[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."); } else { // some other path conflict error: NSLog(@"%@\n", routeError.path.conflict); } } else if ([routeError.path isMalformedPath]) { NSLog(@"Could not create folder because the path is malformed."); } else { // and so on for other errors as desired // some other path error: NSLog(@"%@\n", routeError.path); } } } else if (error) { NSLog(@"%@\n", error); } }];
billymeltdown
9 years agoExplorer | Level 4
I should add, I've also gone over to the API docs themselves (not the obj-c ones) and then I look at the corresponding method there, /create_folder, and still I don't see information I can turn into code the way I'm understanding this. For errors it shows:
CreateFolderError (union)
The value will be one of the following datatypes:
path WriteError
So I go back to my response block, and I check to see if routeError has an isWriteError property: it does not. So then I click on WriteError in the http docs and it expands:
The value will be one of the following datatypes. New values may be introduced as our API evolves.
malformed_path String? This field is optional.
conflict WriteConflictError Couldn't write to the target path because there was something in the way.
no_write_permission Void The user doesn't have permissions to write to the target location.
insufficient_space Void The user doesn't have enough available space (bytes) to write more data.
disallowed_name Void Dropbox will not save the file or folder because of its name.
Okay, cool, so I go back to the readme and it says
> To properly handle union types, you should call each of the is<TAG_STATE> methods associated with the union.
Okay, so, what methods are available, how do I determine those with the info above? All I see is "isPath" ....
- Greg-DB9 years agoDropbox Staff
For each API call, you'll want to handle both the route error (for errors specific to that call) as well as the general error (for errors that can happen on any call).
For the route specific error for createFolder, which is DBFILESCreateFolderError, there is only the isPath case, since that error doesn't have any other scenarios. (The example in the README is for the delete call, which has a different set of possible route-specific errors, under DBFILESDeleteError.)
To see what is possible for any particular error, I recommend checking the Objective-C SDK documentation for that error type, e.g., DBFILESCreateFolderError, which lists just isPath. (You can look at the HTTP documenation, as you linked to, but the names won't always be exactly the same, as they get translated slightly for the SDK.)
So, if DBFILESCreateFolderError isPath is true, you can then access the DBFILESWriteError in it via the path field.
Here's a more elaborate sample for createFolder showing that:
[[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."); } else { // some other path conflict error: NSLog(@"%@\n", routeError.path.conflict); } } else if ([routeError.path isMalformedPath]) { NSLog(@"Could not create folder because the path is malformed."); } else { // and so on for other errors as desired // some other path error: NSLog(@"%@\n", routeError.path); } } } else if (error) { NSLog(@"%@\n", error); } }];
- billymeltdown9 years agoExplorer | Level 4
Ohhhhh, okay I get it! Thanks, Greg!
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,878 PostsLatest Activity: 5 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!