errorsext

package
v5.26.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2024 License: Apache-2.0, MIT Imports: 6 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMaxAttemptsReached is a placeholder error to use when some retryable even has reached its maximum number of
	// attempts.
	ErrMaxAttemptsReached = errors.New("max attempts reached")
)

Functions

func DoRetryable added in v5.17.0

func DoRetryable[T, E any](ctx context.Context, isRetryFn IsRetryableFn[E], onRetryFn OnRetryFn[E], fn RetryableFn[T, E]) resultext.Result[T, E]

DoRetryable will execute the provided functions code and automatically retry using the provided retry function.

func IsRetryableHTTP

func IsRetryableHTTP(err error) (retryType string, isRetryable bool)

IsRetryableHTTP returns if the provided error is considered retryable HTTP error. It also returns the type, in string form, for optional logging and metrics use.

func IsRetryableNetwork

func IsRetryableNetwork(err error) (retryType string, isRetryable bool)

IsRetryableNetwork returns if the provided error is a retryable network related error. It also returns the type, in string form, for optional logging and metrics use.

func IsTemporary

func IsTemporary(err error) bool

IsTemporary returns true if the provided error is considered retryable temporary error by testing if it complies with an interface implementing `Temporary() bool` and calling the function.

func IsTemporaryConnection

func IsTemporaryConnection(err error) (retryType string, isRetryable bool)

IsTemporaryConnection returns if the provided error was a low level retryable connection error. It also returns the type, in string form, for optional logging and metrics use.

func IsTimeout

func IsTimeout(err error) bool

IsTimeout returns true if the provided error is considered a retryable timeout error by testing if it complies with an interface implementing `Timeout() bool` and calling the function.

Types

type IsRetryableFn added in v5.17.0

type IsRetryableFn[E any] func(err E) (reason string, isRetryable bool)

IsRetryableFn is called to determine if the error is retryable and optionally returns the reason for logging and metrics.

type OnRetryFn added in v5.17.0

type OnRetryFn[E any] func(ctx context.Context, originalErr E, reason string, attempt int) optionext.Option[E]

OnRetryFn is called after IsRetryableFn returns true and before the retry is attempted.

this allows for interception, short-circuiting and adding of backoff strategies.

type RetryableFn added in v5.17.0

type RetryableFn[T, E any] func(ctx context.Context) resultext.Result[T, E]

RetryableFn is a function that can be retried.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL