bitbucket.org/ai69/amoy@v0.2.3/error.go (about) 1 package amoy 2 3 import ( 4 "errors" 5 "net" 6 "os" 7 ) 8 9 // ErrorCause returns the cause of an error. 10 func ErrorCause(err error) error { 11 for { 12 cause := errors.Unwrap(err) 13 if cause == nil { 14 return err 15 } 16 err = cause 17 } 18 } 19 20 // IsTimeoutError checks if error is timeout error. 21 func IsTimeoutError(err error) bool { 22 if err == nil { 23 return false 24 } 25 return os.IsTimeout(err) 26 } 27 28 // IsNoNetworkError indicates whether the error is caused by no network. 29 func IsNoNetworkError(err error) bool { 30 if err == nil { 31 return false 32 } 33 var dnsError *net.DNSError 34 return errors.As(err, &dnsError) 35 }