"Fossies" - the Fresh Open Source Software Archive

Member "gdrive-2.1.1/drive/errors.go" (28 May 2021, 719 Bytes) of package /linux/misc/gdrive-2.1.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Go source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 package drive
    2 
    3 import (
    4     "golang.org/x/net/context"
    5     "google.golang.org/api/googleapi"
    6     "time"
    7 )
    8 
    9 const MaxErrorRetries = 5
   10 
   11 func isBackendOrRateLimitError(err error) bool {
   12     return isBackendError(err) || isRateLimitError(err)
   13 }
   14 
   15 func isBackendError(err error) bool {
   16     if err == nil {
   17         return false
   18     }
   19 
   20     ae, ok := err.(*googleapi.Error)
   21     return ok && ae.Code >= 500 && ae.Code <= 599
   22 }
   23 
   24 func isRateLimitError(err error) bool {
   25     if err == nil {
   26         return false
   27     }
   28 
   29     ae, ok := err.(*googleapi.Error)
   30     return ok && ae.Code == 403
   31 }
   32 
   33 func isTimeoutError(err error) bool {
   34     return err == context.Canceled
   35 }
   36 
   37 func exponentialBackoffSleep(try int) {
   38     seconds := pow(2, try)
   39     time.Sleep(time.Duration(seconds) * time.Second)
   40 }