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 getting exceptions at times that I shouldn't - i.e. there IS a folder there - and (2) I'm also having trouble getting further info from the exception. This is in C#/.NET in VS2017 on Win10.
What I've found is when I set a beakpoint and step through the code, it works perfectly! But when I remove the breakpoint I sometimes get exceptions when I shouldn't (so apparently some kind of timing issue). The relevant code is (note Dataservice is a Dropbox instance, accessed through an Interface)...
public async Task<Metadata> GetFolderMetadata(string path)
{
if (DropboxDebug) { log.SMAdebug("GetFolderMetadata has started");};
using (DropboxClient DxClient=new DropboxClient(AccessToken)){
try {
Metadata metadata =await DxClient.Files.GetMetadataAsync(path);
if (DropboxDebug) { log.SMAdebug("GetFolderMetadata has ended normally");};
return metadata;
}
catch {
if (DropboxDebug) {log.SMAdebug("Exception in GetFolderMetadata");};
return null;
}
}
}
var folderMetadata=await DataService.GetFolderMetadata(thisFolder);
if (folderMetadata!=null) {
if (VMdebug) {
System.Diagnostics.Debug.WriteLine(string.Format("{0} already exists - skipping",thisFolder));
};
continue;
} else {
if (VMdebug) {log.SMAdebug("Creating folder",thisFolder);};
await DataService.CreateFolder(thisFolder,false);
};
I did try to get further info from the exception by putting "catch (ApiException e) {...", but it wanted further info, and since I was getting "ApiException'1", I tried "catch (Apiexception<1>) {...", but VS didn't like that either. Not sure what syntax I need to put to get further info from this exception (which, as noted, being returned when it shouldn't when no breakpoints).
Not sure if there's an intentional limit to how often you can query the API, or if I'm just running into a glitch? i.e. not sure if I need to be dealing with it (presumably by sticking in a delay, though note I still would like to know how to get further info from the exception to confirm what it's complaining about), or if maybe there's something you need to look at on your end.
thanks,
Donald.