mirror of
https://github.com/go-micro/go-micro.git
synced 2024-11-24 08:02:32 +02:00
f23638c036
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
36 lines
824 B
Go
36 lines
824 B
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/micro/go-micro/v2/errors"
|
|
)
|
|
|
|
// note that returning either false or a non-nil error will result in the call not being retried
|
|
type RetryFunc func(ctx context.Context, req Request, retryCount int, err error) (bool, error)
|
|
|
|
// RetryAlways always retry on error
|
|
func RetryAlways(ctx context.Context, req Request, retryCount int, err error) (bool, error) {
|
|
return true, nil
|
|
}
|
|
|
|
// RetryOnError retries a request on a 500 or timeout error
|
|
func RetryOnError(ctx context.Context, req Request, retryCount int, err error) (bool, error) {
|
|
if err == nil {
|
|
return false, nil
|
|
}
|
|
|
|
e := errors.Parse(err.Error())
|
|
if e == nil {
|
|
return false, nil
|
|
}
|
|
|
|
switch e.Code {
|
|
// retry on timeout or internal server error
|
|
case 408, 500:
|
|
return true, nil
|
|
default:
|
|
return false, nil
|
|
}
|
|
}
|