throttle_error.go (1725B)
1 package retry 2 3 import ( 4 "errors" 5 6 "github.com/aws/aws-sdk-go-v2/aws" 7 ) 8 9 // IsErrorThrottle provides the interface of an implementation to determine if 10 // a error response from an operation is a throttling error. 11 type IsErrorThrottle interface { 12 IsErrorThrottle(error) aws.Ternary 13 } 14 15 // IsErrorThrottles is a collection of checks to determine of the error a 16 // throttle error. Iterates through the checks and returns the state of 17 // throttle if any check returns something other than unknown. 18 type IsErrorThrottles []IsErrorThrottle 19 20 // IsErrorThrottle returns if the error is a throttle error if any of the 21 // checks in the list return a value other than unknown. 22 func (r IsErrorThrottles) IsErrorThrottle(err error) aws.Ternary { 23 for _, re := range r { 24 if v := re.IsErrorThrottle(err); v != aws.UnknownTernary { 25 return v 26 } 27 } 28 return aws.UnknownTernary 29 } 30 31 // IsErrorThrottleFunc wraps a function with the IsErrorThrottle interface. 32 type IsErrorThrottleFunc func(error) aws.Ternary 33 34 // IsErrorThrottle returns if the error is a throttle error. 35 func (fn IsErrorThrottleFunc) IsErrorThrottle(err error) aws.Ternary { 36 return fn(err) 37 } 38 39 // ThrottleErrorCode determines if an attempt should be retried based on the 40 // API error code. 41 type ThrottleErrorCode struct { 42 Codes map[string]struct{} 43 } 44 45 // IsErrorThrottle return if the error is a throttle error based on the error 46 // codes. Returns unknown if the error doesn't have a code or it is unknown. 47 func (r ThrottleErrorCode) IsErrorThrottle(err error) aws.Ternary { 48 var v interface{ ErrorCode() string } 49 50 if !errors.As(err, &v) { 51 return aws.UnknownTernary 52 } 53 54 _, ok := r.Codes[v.ErrorCode()] 55 if !ok { 56 return aws.UnknownTernary 57 } 58 59 return aws.TrueTernary 60 }