normalize

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package normalize provides shared provider error normalization helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeError

func DecodeError(provider string, err error) error

DecodeError wraps decode/parsing failures as provider-specific decode errors.

func DecodeErrorWithBody added in v0.16.0

func DecodeErrorWithBody(provider string, err error, body []byte) error

DecodeErrorWithBody wraps decode/parsing failures as provider-specific decode errors, additionally preserving the raw response body (truncated) that failed to decode so callers can inspect what the provider actually sent back.

func NetworkError

func NetworkError(provider string, err error) error

NetworkError wraps transport failures as provider-specific network errors.

func OpenAIStyleProviderError

func OpenAIStyleProviderError(provider string, status int, body []byte, requestID string) error

OpenAIStyleProviderError normalizes providers that use OpenAI-style error envelopes.

func ProviderError

func ProviderError(provider string, status int, requestID, code, message string, sentinel error) error

ProviderError constructs a normalized ProviderError. If message is empty, HTTP status text is used. If sentinel is nil, default status-based mapping is applied.

func RequireAPIKey added in v0.17.0

func RequireAPIKey(provider string, key core.Secret) error

RequireAPIKey returns a descriptive *core.ProviderError wrapping core.ErrUnauthorized when the API key is empty (or whitespace-only), so a provider can fail fast before making an unauthenticated request. Returns nil when the key is present.

func SentinelForStatus

func SentinelForStatus(status int) error

SentinelForStatus maps an HTTP status code to a core sentinel error.

func SentinelForStatusWithOverrides

func SentinelForStatusWithOverrides(status int, overrides map[int]error) error

SentinelForStatusWithOverrides maps an HTTP status code to a core sentinel error, then applies any exact status overrides from the provided map.

func WithRetryAfter added in v1.0.0

func WithRetryAfter(err error, headers ...http.Header) error

WithRetryAfter attaches a server-advised retry delay to a normalized ProviderError. It accepts the standard Retry-After header plus common provider-specific millisecond and reset headers.

Types

This section is empty.

Jump to

Keyboard shortcuts

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