From 74082d21ae2b817b7ca7bab5a3bc5a371261fc54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?France=CC=81=20Wilke?= <francewilke@gmail.com> Date: Tue, 6 Jun 2023 16:28:44 +0200 Subject: [PATCH] #34 Add new function for IsRetryableErrorOrShouldFail --- errors/error.go | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/errors/error.go b/errors/error.go index 65ac2fd..d20acd5 100644 --- a/errors/error.go +++ b/errors/error.go @@ -263,10 +263,36 @@ func IsRetryableError(err error) bool { return true } - // Explicitly check for and return false for any 400s as well + 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 + return false, false } - return 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 } -- GitLab