We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
donaldp
7 years agoCollaborator | Level 9
Problem with GetMetadataAsync
Hi, I'm trying to test for the existence of a folder so as not to repeat myself. My understanding is that you use GetMetadataAsync and treat the folder as not there if you get an exception. (1) I'm ...
Greg-DB
Dropbox Community Moderator
7 years agoHi Donald, there is a rate limiting system on the Dropbox API, but it's relatively generous. If you are hitting it though, the Dropbox API will return an explicit rate limiting error. It's possible you're missing that since you're not inspecting what kind of exception you're getting, as you mentioned. Likewise, there are other exceptions that can occur on GetMetadataAsync other than just 'not_found'.
Here's an example of how you can break out some of the various error cases:
try
{
Metadata res = await client.Files.GetMetadataAsync(path);
Console.WriteLine("{0}", res);
}
catch (ApiException<GetMetadataError> e)
{
if (e.ErrorResponse.IsPath) {
if (e.ErrorResponse.AsPath.Value.IsNotFound) {
Console.WriteLine("Path not found!");
} else if (e.ErrorResponse.AsPath.Value.IsMalformedPath) {
Console.WriteLine("Malformed path!");
} // and so on for the other .Is* methods as desired
else {
Console.WriteLine("LookupError: {0}", e.ErrorResponse.AsPath.Value);
}
} else {
Console.WriteLine("GetMetadataError: {0}", e);
}
} catch (Exception e)
{
Console.WriteLine("Some other error: {0}", e);
}donaldp
7 years agoCollaborator | Level 9
Hi Greg,
catch (ApiException<GetMetadataError> e)
Thanks for that! That was the missing piece of the puzzle. I can confirm now that I'm getting "path/not_found/..." for a folder that has definitely already been created (FYI I'm dealing with input that has duplicates, and editing them out is not practical, so I'm just looking to skip processing the duplicates. i.e. test if that folder has already been created).
I'm also getting a lot of "Exception thrown: 'Dropbox.Api.RetryException' in Dropbox.Api.dll" messages, though it's not crashing the program, and also not being caught by my general catch statement for this line of code (perhaps because it's coming from somewhere in Dropbox.Api?). Note: I already had a 500ms delay due to part of the process being a Bing image search - which is limited to 3 per second - however I doubled it to 1000, and STILL getting this "not found" and retry exceptions for a folder that was already created 1000ms previously. 2000ms, same thing. 5000ms, same thing. Becoming ridiculous now. As noted, works perfectly with breakpoints, just not working at normal speed. Not sure how to fix this?
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If 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, Facebook or Instagram.
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!