Skip to content
Snippets Groups Projects

Resolve "Cater for errors being nil and update checks for retryable errors"

Files

+ 33
1
@@ -9,6 +9,7 @@ import (
)
// CustomError implements the following interfaces:
//
// error
// github.com/pkg/errors: Cause
type CustomError struct {
@@ -251,7 +252,7 @@ func IsRetryableError(err error) bool {
if code == 0 {
return false
}
// 429 should always retry
if code == http.StatusTooManyRequests {
return true
@@ -264,3 +265,34 @@ func IsRetryableError(err error) bool {
return false
}
func IsRetryableErrorOrShouldFail(err error) (shouldRetry bool, shouldFail bool) {
if err == nil {
return false, false
}
// Check for retryable
if IsRetryableError(err) {
return true, false
}
code := HTTPCode(err)
// If no HTTP code in the error, just fail but don't retry
if code == 0 {
return false, true
}
// Explicitly check for 400s, and don't retry or fail
if code >= 400 && code < 500 {
return false, false
}
// Explicitly check for 200s, for a fail-safe
if code >= 200 && code < 300 {
return false, false
}
// If we got here, we should fail normally
return false, true
}
Loading