Skip to content
Snippets Groups Projects
Commit 91f710a3 authored by Francé Wilke's avatar Francé Wilke
Browse files

Merge branch '34-cater-for-errors-being-nil-and-update-checks-for-retryable-errors' into 'main'

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

See merge request !36
parents d55098dd 74082d21
No related branches found
No related tags found
1 merge request!36Resolve "Cater for errors being nil and update checks for retryable errors"
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
) )
// CustomError implements the following interfaces: // CustomError implements the following interfaces:
//
// error // error
// github.com/pkg/errors: Cause // github.com/pkg/errors: Cause
type CustomError struct { type CustomError struct {
...@@ -264,3 +265,34 @@ func IsRetryableError(err error) bool { ...@@ -264,3 +265,34 @@ func IsRetryableError(err error) bool {
return false 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
}
...@@ -102,9 +102,15 @@ func HTTPCodeOnly(code int) error { ...@@ -102,9 +102,15 @@ func HTTPCodeOnly(code int) error {
} }
func HTTPWithError(code int, err error) error { func HTTPWithError(code int, err error) error {
var errorMessage string
// This check is here just as a failsafe to seg faults, if err is nil then just return assign an empty string as message.
if err != nil {
errorMessage = err.Error()
}
wrappedErr := &CustomError{ wrappedErr := &CustomError{
code: code, code: code,
message: err.Error(), message: errorMessage,
caller: GetCaller(2), caller: GetCaller(2),
cause: err, cause: err,
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment