-
Notifications
You must be signed in to change notification settings - Fork 175
/
errors.go
58 lines (46 loc) · 878 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package errors
import (
stdErrors "errors"
"fmt"
)
type Unwrappable interface {
Unwrap() error
}
type RetryableConflictError interface {
IsRetryableConflict() bool
Unwrappable
error
}
func IsRetryableConflictError(originalErr error) bool {
if originalErr == nil {
return false
}
currentErr := originalErr
for {
var retryable RetryableConflictError
if !stdErrors.As(currentErr, &retryable) {
return false
}
if retryable.IsRetryableConflict() {
return true
}
currentErr = retryable.Unwrap()
}
}
type retryableConflictError struct {
error
}
func NewRetryableConflictError(
msg string,
vals ...interface{},
) error {
return &retryableConflictError{
error: fmt.Errorf(msg, vals...),
}
}
func (retryableConflictError) IsRetryableConflict() bool {
return true
}
func (err *retryableConflictError) Unwrap() error {
return err.error
}