Documentation
¶
Index ¶
- func ParseRetryAfter(header http.Header, now time.Time) (time.Duration, bool)
- func ParseRetryAfterMillisecondsValue(value string) (time.Duration, bool)
- func ParseRetryAfterValue(value string, now time.Time) (time.Duration, bool)
- func ReadBodyAndClose(resp *http.Response, limit int64) []byte
- func RetryableStatus(statusCode int) bool
- type StatusError
- func NewStatusError(provider string, resp *http.Response, body []byte) *StatusError
- func NewStatusErrorFromResponse(provider string, resp *http.Response) *StatusError
- func NewStatusErrorMessage(message string, resp *http.Response, body []byte) *StatusError
- func NewStatusErrorMessageFromResponse(resp *http.Response, buildMessage func(body []byte) string) *StatusError
- func NewStatusErrorMessageString(message string, statusCode int, status string, header http.Header, body string) *StatusError
- func NewStatusErrorMessagef(resp *http.Response, body []byte, format string, args ...any) *StatusError
- func NewStatusErrorString(provider string, statusCode int, status string, header http.Header, ...) *StatusError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseRetryAfter ¶
ParseRetryAfter parses Retry-After metadata from HTTP headers. It supports:
- Retry-After-Ms / retry-after-ms: integer milliseconds
- Retry-After: integer seconds
- Retry-After: HTTP-date
func ParseRetryAfterMillisecondsValue ¶
ParseRetryAfterMillisecondsValue parses a Retry-After-Ms header value.
func ParseRetryAfterValue ¶
ParseRetryAfterValue parses a Retry-After header value as either seconds or an HTTP-date. now is used for deterministic tests; pass a zero time to use time.Now().
func ReadBodyAndClose ¶
ReadBodyAndClose reads resp.Body and closes it. If limit is positive, at most limit bytes are returned. Read errors are intentionally ignored because status error bodies are best-effort diagnostics.
func RetryableStatus ¶
RetryableStatus reports whether statusCode is commonly transient and worth retrying for provider/API calls.
Types ¶
type StatusError ¶
type StatusError struct {
Provider string
StatusCode int
Status string
Body string
Header http.Header
Message string
}
StatusError captures a non-success HTTP response from a provider while preserving response headers for retry/backoff decisions (notably Retry-After). The Error text remains provider-oriented for user display.
func NewStatusError ¶
func NewStatusError(provider string, resp *http.Response, body []byte) *StatusError
NewStatusError returns a typed status error using the default "<provider> API error (status N): body" message shape. If provider is empty, the message starts with "API error".
func NewStatusErrorFromResponse ¶
func NewStatusErrorFromResponse(provider string, resp *http.Response) *StatusError
NewStatusErrorFromResponse reads and closes resp.Body, then returns a typed status error. It is intended for the common non-2xx path where callers do not need to inspect the body separately.
func NewStatusErrorMessage ¶
func NewStatusErrorMessage(message string, resp *http.Response, body []byte) *StatusError
NewStatusErrorMessage returns a typed status error with a caller-supplied display message. Use this when existing code has a more specific error string that should be preserved while still attaching status/header metadata.
func NewStatusErrorMessageFromResponse ¶
func NewStatusErrorMessageFromResponse(resp *http.Response, buildMessage func(body []byte) string) *StatusError
NewStatusErrorMessageFromResponse reads and closes resp.Body, then returns a typed status error with a caller-built display message.
func NewStatusErrorMessageString ¶
func NewStatusErrorMessageString(message string, statusCode int, status string, header http.Header, body string) *StatusError
NewStatusErrorMessageString is like NewStatusErrorMessage but accepts already-normalized body text.
func NewStatusErrorMessagef ¶
func NewStatusErrorMessagef(resp *http.Response, body []byte, format string, args ...any) *StatusError
NewStatusErrorMessagef returns a typed status error with a formatted display message.
func NewStatusErrorString ¶
func NewStatusErrorString(provider string, statusCode int, status string, header http.Header, body string) *StatusError
NewStatusErrorString is like NewStatusError but accepts already-normalized body text.
func (*StatusError) Error ¶
func (e *StatusError) Error() string
func (*StatusError) HTTPStatusCode ¶
func (e *StatusError) HTTPStatusCode() int
HTTPStatusCode exposes the status code for generic retryability checks.
func (*StatusError) RetryAfterDelay ¶
func (e *StatusError) RetryAfterDelay() (time.Duration, bool)
RetryAfterDelay exposes Retry-After metadata for generic retry/backoff logic.