forked from prasmussen/gdrive
-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy patherrors.go
41 lines (31 loc) · 720 Bytes
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package drive
import (
"time"
"golang.org/x/net/context"
"google.golang.org/api/googleapi"
)
const MaxErrorRetries = 5
func isBackendOrRateLimitError(err error) bool {
return isBackendError(err) || isRateLimitError(err)
}
func isBackendError(err error) bool {
if err == nil {
return false
}
ae, ok := err.(*googleapi.Error)
return ok && ae.Code >= 500 && ae.Code <= 599
}
func isRateLimitError(err error) bool {
if err == nil {
return false
}
ae, ok := err.(*googleapi.Error)
return ok && ae.Code == 403
}
func isTimeoutError(err error) bool {
return err == context.Canceled
}
func exponentialBackoffSleep(try int) {
seconds := pow(2, try)
time.Sleep(time.Duration(seconds) * time.Second)
}