retry

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsConflict

func IsConflict(err error) bool

IsConflict reports whether err represents a sync conflict.

func IsRetryableStatus added in v0.6.0

func IsRetryableStatus(code int) bool

IsRetryableStatus reports whether an HTTP status code is worth a retry: 408 (request timeout), 425 (too early), 429 (too many requests), or any 5xx. It is the single source of truth shared by IsTransient and the CalDAV client.

func IsTransient

func IsTransient(err error) bool

IsTransient reports whether err is worth a retry.

func Retry

func Retry[T any](ctx context.Context, opts RetryOptions, fn func(context.Context) (T, error)) (T, error)

Retry reruns fn when it fails with a transient error.

Types

type HTTPError added in v0.6.0

type HTTPError struct {
	Status int
	// Err holds the underlying error (typically a formatted message with
	// the status text and a body excerpt). It is preserved for Error and
	// Unwrap so existing message-based diagnostics keep working.
	Err error
}

HTTPError carries an HTTP status code as a typed field. Transient and conflict classification can then rely on the real status instead of a scrape of the error string. String scrape is fragile. Any wrap that prepends a numeric token (a batch index, a host:port segment) would shadow the status and mis-route retries.

func NewHTTPError added in v0.6.0

func NewHTTPError(status int, err error) *HTTPError

NewHTTPError builds an HTTPError for the given status. The message is supplied by the caller so the rich, human-readable form is preserved.

func (*HTTPError) Error added in v0.6.0

func (e *HTTPError) Error() string

func (*HTTPError) Unwrap added in v0.6.0

func (e *HTTPError) Unwrap() error

type RetryOptions

type RetryOptions struct {
	MaxAttempts int
	BaseDelay   time.Duration
	MaxDelay    time.Duration
}

RetryOptions controls retry behavior for transient network operations.

type TransientError added in v0.6.0

type TransientError struct {
	Err        error
	RetryAfter time.Duration
}

TransientError marks an error as retryable. It optionally carries a server-requested minimum delay before the next attempt. One example is the value of an HTTP Retry-After header on a 429 or 503 response. A zero RetryAfter means the server gave no hint. Normal exponential backoff then applies.

func (*TransientError) Error added in v0.6.0

func (e *TransientError) Error() string

func (*TransientError) Unwrap added in v0.6.0

func (e *TransientError) Unwrap() error

Jump to

Keyboard shortcuts

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