backport micro 820f59869617dee18c9a699c8e01d7a6b080f854
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
8fd745eab0
commit
f63ff80d46
@ -100,7 +100,7 @@ var (
|
|||||||
// DefaultBackoff is the default backoff function for retries
|
// DefaultBackoff is the default backoff function for retries
|
||||||
DefaultBackoff = exponentialBackoff
|
DefaultBackoff = exponentialBackoff
|
||||||
// DefaultRetry is the default check-for-retry function for retries
|
// DefaultRetry is the default check-for-retry function for retries
|
||||||
DefaultRetry = RetryOnError
|
DefaultRetry = RetryNever
|
||||||
// DefaultRetries is the default number of times a request is tried
|
// DefaultRetries is the default number of times a request is tried
|
||||||
DefaultRetries = 0
|
DefaultRetries = 0
|
||||||
// DefaultRequestTimeout is the default request timeout
|
// DefaultRequestTimeout is the default request timeout
|
||||||
|
@ -14,22 +14,23 @@ func RetryAlways(ctx context.Context, req Request, retryCount int, err error) (b
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RetryNever never retry on error
|
||||||
|
func RetryNever(ctx context.Context, req Request, retryCount int, err error) (bool, error) {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
// RetryOnError retries a request on a 500 or timeout error
|
// RetryOnError retries a request on a 500 or timeout error
|
||||||
func RetryOnError(ctx context.Context, req Request, retryCount int, err error) (bool, error) {
|
func RetryOnError(ctx context.Context, req Request, retryCount int, err error) (bool, error) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
e := errors.Parse(err.Error())
|
me := errors.FromError(err)
|
||||||
if e == nil {
|
switch me.Code {
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
switch e.Code {
|
|
||||||
// retry on timeout or internal server error
|
// retry on timeout or internal server error
|
||||||
case 408, 500:
|
case 408, 500:
|
||||||
return true, nil
|
return true, nil
|
||||||
default:
|
|
||||||
return false, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user