[READ-ONLY] Mirror of https://github.com/andrioid/statesman. xstate inspired schema compatible statechart library for Go
fsm go statecharts
0

Configure Feed

Select the types of activity you want to include in your feed.

statesman / transient.go
880 B 30 lines
1package statesman 2 3import ( 4 "context" 5 "errors" 6 "net" 7 "os" 8) 9 10// IsTransient reports whether err is a retryable transport-level failure: a 11// context or I/O deadline (context.DeadlineExceeded, os.ErrDeadlineExceeded) or a 12// net.Error reporting a timeout. It unwraps via errors.Is / errors.As. 13// 14// It deliberately does NOT classify domain errors (HTTP 4xx/5xx, application 15// failures) or context.Canceled — a cancel is an intentional stop, never a retry. 16// Compose your own predicate around it for domain errors: an error.invoke.<id> 17// guard is where to decide whether a failure is worth spending a retry on. 18func IsTransient(err error) bool { 19 if err == nil { 20 return false 21 } 22 if errors.Is(err, context.DeadlineExceeded) || errors.Is(err, os.ErrDeadlineExceeded) { 23 return true 24 } 25 var ne net.Error 26 if errors.As(err, &ne) { 27 return ne.Timeout() 28 } 29 return false 30}