go-micro.dev/v5@v5.12.0/client/retry.go (about) 1 package client 2 3 import ( 4 "context" 5 6 "go-micro.dev/v5/errors" 7 ) 8 9 // note that returning either false or a non-nil error will result in the call not being retried. 10 type RetryFunc func(ctx context.Context, req Request, retryCount int, err error) (bool, error) 11 12 // RetryAlways always retry on error. 13 func RetryAlways(ctx context.Context, req Request, retryCount int, err error) (bool, error) { 14 return true, nil 15 } 16 17 // RetryOnError retries a request on a 500 or timeout error. 18 func RetryOnError(ctx context.Context, req Request, retryCount int, err error) (bool, error) { 19 if err == nil { 20 return false, nil 21 } 22 23 e := errors.Parse(err.Error()) 24 if e == nil { 25 return false, nil 26 } 27 28 switch e.Code { 29 // Retry on timeout, not on 500 internal server error, as that is a business 30 // logic error that should be handled by the user. 31 case 408: 32 return true, nil 33 default: 34 return false, nil 35 } 36 }