From 8fb707e16dab63609bf29b0eac65cf6395af8942 Mon Sep 17 00:00:00 2001 From: Mathieu Carbou Date: Wed, 5 Dec 2018 10:11:41 -0500 Subject: [PATCH] Fixes #1788: Retry-After support for Dropbox backend --- backend/dropbox/dropbox.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/backend/dropbox/dropbox.go b/backend/dropbox/dropbox.go index d6b18fdcf..e4ad4ba79 100644 --- a/backend/dropbox/dropbox.go +++ b/backend/dropbox/dropbox.go @@ -31,6 +31,7 @@ import ( "time" "github.com/dropbox/dropbox-sdk-go-unofficial/dropbox" + "github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/auth" "github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/common" "github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/files" "github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/sharing" @@ -203,7 +204,16 @@ func shouldRetry(err error) (bool, error) { return false, err } baseErrString := errors.Cause(err).Error() - // FIXME there is probably a better way of doing this! + // handle any official Retry-After header from Dropbox's SDK first + switch e := err.(type) { + case auth.RateLimitAPIError: + if e.RateLimitError.RetryAfter > 0 { + fs.Debugf(baseErrString, "Too many requests or write operations. Trying again in %d seconds.", e.RateLimitError.RetryAfter) + time.Sleep(time.Duration(e.RateLimitError.RetryAfter) * time.Second) + } + return true, err + } + // Keep old behaviour for backward compatibility if strings.Contains(baseErrString, "too_many_write_operations") || strings.Contains(baseErrString, "too_many_requests") { return true, err }