forked from armon/go-chord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
44 lines (34 loc) · 843 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
42
43
44
package buddystore
import (
"fmt"
"strings"
)
type BuddyStoreError struct {
Err string
Transient bool
}
func PermanentError(str string, args ...interface{}) BuddyStoreError {
return BuddyStoreError{Err: fmt.Sprintf(str, args), Transient: false}
}
func TransientError(str string, args ...interface{}) BuddyStoreError {
return BuddyStoreError{Err: fmt.Sprintf(str, args), Transient: true}
}
func (bse BuddyStoreError) Error() string {
return bse.Err
}
func (bse BuddyStoreError) Temporary() bool {
return bse.Transient
}
func (bse BuddyStoreError) Timeout() bool {
return false
}
func isRetryable(err error) bool {
if err == nil {
return false
}
if nerr, ok := err.(BuddyStoreError); ok && nerr.Temporary() {
return true
}
// To support pure string errors
return strings.Contains(err.Error(), "[Retryable]")
}