<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Exemplary C# Code to Handle Exception Value Retry-After when using the .NET API? in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-get-at-Retry-After-when-using-the-NET-API-and-using/m-p/593448#M27605</link>
    <description>&lt;P&gt;&lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/1398431"&gt;@Tech Dev Oldsmar&lt;/a&gt; It looks like you have the right idea here; you're grabbing the Retry-After from 'e.ErrorResponse.RetryAfter'. (Exactly how you structure your app with respect to exception messaging and thread handling is up to you though. E.g., it seems like in your sample you wait and then re-throw the exception.) I notice that your 'Console.WriteLine' line right before that seems wrong though; you're plugging in 'e.Message' when it seems like you meant to plug in the number of seconds, which would be 'e.ErrorResponse.RetryAfter' instead. Also I believe you should just do 'catch (RateLimitException e)' instead of 'catch (ApiException&amp;lt;RateLimitException&amp;gt; e)'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, in the other exception handling you have, note that we don't recommend doing string comparisons like that. The best practice is to instead use the provided structured error objects, like this:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;catch (ApiException&amp;lt;CreateFolderError&amp;gt; e)
{

	// you can write your error handling to be as granular as you wish, using as much or as little of this as you want:
	if (e.ErrorResponse.IsPath) { 
		if (e.ErrorResponse.AsPath.Value.IsConflict)
        {
			if (e.ErrorResponse.AsPath.Value.AsConflict.IsConflict)
            {
				if (e.ErrorResponse.AsPath.Value.AsConflict.Value.IsFolder)
				{
					Console.WriteLine("A folder already exists at this path");
					// whatever handling you need to do
				}
				else if (e.ErrorResponse.AsPath.Value.AsConflict.Value.IsFile)
				{
					Console.WriteLine("A file already exists at this path");
					// whatever handling you need to do
				}
				else if (e.ErrorResponse.AsPath.Value.AsConflict.Value.IsFileAncestor)
				{
					Console.WriteLine("A file already exists at this a parent of this path");
					// whatever handling you need to do
				}
				else if (e.ErrorResponse.AsPath.Value.AsConflict.Value.IsOther) {
					Console.WriteLine("Other error");
					// whatever handling you need to do
				}
			} // else... and so on as desired
		} // else... and so on as desired
	} // else... and so on as desired
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 26 Apr 2022 16:14:59 GMT</pubDate>
    <dc:creator>Greg-DB</dc:creator>
    <dc:date>2022-04-26T16:14:59Z</dc:date>
    <item>
      <title>How to get at Retry-After when using the .NET API and using UploadAsync to upload</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-get-at-Retry-After-when-using-the-NET-API-and-using/m-p/479388#M24204</link>
      <description>&lt;P&gt;We use the .NET API to upload files using UploadAsync&lt;/P&gt;
&lt;P&gt;I recently got an error: System.AggregateException: One or more errors occurred. ---&amp;gt; Dropbox.Api.RateLimitException: too_many_requests/.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, I need to ratelimit, fine, I'm OK with that. Elsewhere there's talk about a Retry-After header that tell you how long to wait before retrying. But how do I get at that from C# ??? So far, I can only guess how long to wait, and that's just silly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There ought to be a way to get at that value, right ?&lt;/P&gt;</description>
      <pubDate>Mon, 14 Dec 2020 21:33:01 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-get-at-Retry-After-when-using-the-NET-API-and-using/m-p/479388#M24204</guid>
      <dc:creator>LinuxCub</dc:creator>
      <dc:date>2020-12-14T21:33:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to get at Retry-After when using the .NET API and using UploadAsync to upload</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-get-at-Retry-After-when-using-the-NET-API-and-using/m-p/479407#M24205</link>
      <description>&lt;P&gt;Yes, you should be able to access that in &lt;A href="https://dropbox.github.io/dropbox-sdk-dotnet/html/P_Dropbox_Api_RateLimitException_RetryAfter.htm" target="_blank"&gt;the&amp;nbsp;RateLimitException.RetryAfter property&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Dec 2020 21:38:52 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-get-at-Retry-After-when-using-the-NET-API-and-using/m-p/479407#M24205</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2020-12-14T21:38:52Z</dc:date>
    </item>
    <item>
      <title>Exemplary C# Code to Handle Exception Value Retry-After when using the .NET API?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-get-at-Retry-After-when-using-the-NET-API-and-using/m-p/593424#M27604</link>
      <description>&lt;P&gt;Hunting for some exemplary C# (and or best practice advice) on the &lt;STRONG&gt;RateLimitingException&lt;/STRONG&gt; but not finding much.&amp;nbsp; Not sure how to test this but I was thinking:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;        public static async Task&amp;lt;FolderMetadata&amp;gt; CreateFolder2(DropboxClient client, string path)
        {
            //https://github.com/dropbox/dropbox-sdk-dotnet/blob/main/dropbox-sdk-dotnet/Examples/SimpleTest/Program.cs
            var accountInfo = await client.Users.GetCurrentAccountAsync(); // FOR ACCESSING TEAM FOLDERS
            client = client.WithPathRoot(new PathRoot.Root(accountInfo.RootInfo.RootNamespaceId));
            var folderArg = new CreateFolderArg(path, true);
            try
            {
                var folder = await client.Files.CreateFolderV2Async(folderArg);
                
                return folder.Metadata;
            }
            catch (ApiException&amp;lt;CreateFolderError&amp;gt; e)
            {
                if (e.Message.StartsWith("path/conflict/folder"))
                {
                    Console.WriteLine("Folder already exists... Skipping create");
                    return new FolderMetadata();
                }
                else
                {
                    throw e;
                }
            }
            catch (ApiException&amp;lt;RateLimitException&amp;gt; e)
            {
                Console.WriteLine("Rate Limit Error, try again after " + e.Message +  " seconds. Setting delay");
                Thread.Sleep(Convert.ToInt32(e.ErrorResponse.RetryAfter) * 1000);
                throw e;
            }
        }&lt;/LI-CODE&gt;&lt;P&gt;Is this in the right ballpark?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2022 14:45:58 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-get-at-Retry-After-when-using-the-NET-API-and-using/m-p/593424#M27604</guid>
      <dc:creator>Tech Dev Oldsmar</dc:creator>
      <dc:date>2022-04-26T14:45:58Z</dc:date>
    </item>
    <item>
      <title>Re: Exemplary C# Code to Handle Exception Value Retry-After when using the .NET API?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-get-at-Retry-After-when-using-the-NET-API-and-using/m-p/593448#M27605</link>
      <description>&lt;P&gt;&lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/1398431"&gt;@Tech Dev Oldsmar&lt;/a&gt; It looks like you have the right idea here; you're grabbing the Retry-After from 'e.ErrorResponse.RetryAfter'. (Exactly how you structure your app with respect to exception messaging and thread handling is up to you though. E.g., it seems like in your sample you wait and then re-throw the exception.) I notice that your 'Console.WriteLine' line right before that seems wrong though; you're plugging in 'e.Message' when it seems like you meant to plug in the number of seconds, which would be 'e.ErrorResponse.RetryAfter' instead. Also I believe you should just do 'catch (RateLimitException e)' instead of 'catch (ApiException&amp;lt;RateLimitException&amp;gt; e)'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, in the other exception handling you have, note that we don't recommend doing string comparisons like that. The best practice is to instead use the provided structured error objects, like this:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;catch (ApiException&amp;lt;CreateFolderError&amp;gt; e)
{

	// you can write your error handling to be as granular as you wish, using as much or as little of this as you want:
	if (e.ErrorResponse.IsPath) { 
		if (e.ErrorResponse.AsPath.Value.IsConflict)
        {
			if (e.ErrorResponse.AsPath.Value.AsConflict.IsConflict)
            {
				if (e.ErrorResponse.AsPath.Value.AsConflict.Value.IsFolder)
				{
					Console.WriteLine("A folder already exists at this path");
					// whatever handling you need to do
				}
				else if (e.ErrorResponse.AsPath.Value.AsConflict.Value.IsFile)
				{
					Console.WriteLine("A file already exists at this path");
					// whatever handling you need to do
				}
				else if (e.ErrorResponse.AsPath.Value.AsConflict.Value.IsFileAncestor)
				{
					Console.WriteLine("A file already exists at this a parent of this path");
					// whatever handling you need to do
				}
				else if (e.ErrorResponse.AsPath.Value.AsConflict.Value.IsOther) {
					Console.WriteLine("Other error");
					// whatever handling you need to do
				}
			} // else... and so on as desired
		} // else... and so on as desired
	} // else... and so on as desired
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2022 16:14:59 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-get-at-Retry-After-when-using-the-NET-API-and-using/m-p/593448#M27605</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2022-04-26T16:14:59Z</dc:date>
    </item>
    <item>
      <title>Re: Exemplary C# Code to Handle Exception Value Retry-After when using the .NET API?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-get-at-Retry-After-when-using-the-NET-API-and-using/m-p/593466#M27607</link>
      <description>&lt;P&gt;Thank you Greg - very helpful.&amp;nbsp; BTW, the string comparison that caught your eye is from the DBX .NET C#&amp;nbsp;&lt;A href="https://github.com/dropbox/dropbox-sdk-dotnet/blob/main/dropbox-sdk-dotnet/Examples/SimpleTest/Program.cs" target="_self"&gt;sample on Github&amp;nbsp;&lt;/A&gt;(simpletest.cs).&amp;nbsp; I thought it was a little odd too but the .NET samples were nevertheless an amazing help.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2022 16:53:54 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-get-at-Retry-After-when-using-the-NET-API-and-using/m-p/593466#M27607</guid>
      <dc:creator>Tech Dev Oldsmar</dc:creator>
      <dc:date>2022-04-26T16:53:54Z</dc:date>
    </item>
    <item>
      <title>Re: Exemplary C# Code to Handle Exception Value Retry-After when using the .NET API?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-get-at-Retry-After-when-using-the-NET-API-and-using/m-p/593481#M27608</link>
      <description>&lt;P&gt;&lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/1398431"&gt;@Tech Dev Oldsmar&lt;/a&gt; Thanks for pointing that out! I'll ask the team to improve that example.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2022 17:21:37 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-get-at-Retry-After-when-using-the-NET-API-and-using/m-p/593481#M27608</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2022-04-26T17:21:37Z</dc:date>
    </item>
  </channel>
</rss>

