timeout_error.go (1505B)
1 package retry 2 3 import ( 4 "errors" 5 6 "github.com/aws/aws-sdk-go-v2/aws" 7 ) 8 9 // IsErrorTimeout provides the interface of an implementation to determine if 10 // a error matches. 11 type IsErrorTimeout interface { 12 IsErrorTimeout(err error) aws.Ternary 13 } 14 15 // IsErrorTimeouts is a collection of checks to determine of the error is 16 // retryable. Iterates through the checks and returns the state of retryable 17 // if any check returns something other than unknown. 18 type IsErrorTimeouts []IsErrorTimeout 19 20 // IsErrorTimeout returns if the error is retryable if any of the checks in 21 // the list return a value other than unknown. 22 func (ts IsErrorTimeouts) IsErrorTimeout(err error) aws.Ternary { 23 for _, t := range ts { 24 if v := t.IsErrorTimeout(err); v != aws.UnknownTernary { 25 return v 26 } 27 } 28 return aws.UnknownTernary 29 } 30 31 // IsErrorTimeoutFunc wraps a function with the IsErrorTimeout interface. 32 type IsErrorTimeoutFunc func(error) aws.Ternary 33 34 // IsErrorTimeout returns if the error is retryable. 35 func (fn IsErrorTimeoutFunc) IsErrorTimeout(err error) aws.Ternary { 36 return fn(err) 37 } 38 39 // TimeouterError provides the IsErrorTimeout implementation for determining if 40 // an error is a timeout based on type with the Timeout method. 41 type TimeouterError struct{} 42 43 // IsErrorTimeout returns if the error is a timeout error. 44 func (t TimeouterError) IsErrorTimeout(err error) aws.Ternary { 45 var v interface{ Timeout() bool } 46 47 if !errors.As(err, &v) { 48 return aws.UnknownTernary 49 } 50 51 return aws.BoolTernary(v.Timeout()) 52 }