Documentation
¶
Overview ¶
Package errors defines standard error types used across llm-router services.
Index ¶
- Variables
- func ErrorTypeForCode(code string) string
- func MapUpstream(status int, code, errType, message string) *models.ProviderError
- func NewNotFoundError(resource, id string) error
- func NewValidationError(field, message string) error
- func ParseEnvelope(body string) (code, errType, message string)
- func RetryAfterDelay(err error) (int64, bool)
- type APIError
- type NotFoundError
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound is returned when a requested resource does not exist ErrNotFound = errors.New("not found") // ErrAlreadyExists is returned when attempting to create a duplicate resource ErrAlreadyExists = errors.New("already exists") // ErrInvalidInput is returned when input validation fails ErrInvalidInput = errors.New("invalid input") ErrUnauthorized = errors.New("unauthorized") // ErrForbidden is returned for authorization failures ErrForbidden = errors.New("forbidden") // ErrModelNotAllowed is returned when a token's rules forbid the requested model ErrModelNotAllowed = errors.New("model not allowed by token rules") // ErrProviderNotAllowed is returned when a token's rules forbid the requested provider ErrProviderNotAllowed = errors.New("provider not allowed by token rules") // ErrCredentialNotAllowed is returned when a token's rules forbid all credentials for a provider ErrCredentialNotAllowed = errors.New("no allowed credential available for provider") // ErrNoCredential is returned when no credential is available for a provider ErrNoCredential = errors.New("no credential available for provider") // ErrProviderNotFound is returned when no provider can handle a given ModelId ErrProviderNotFound = errors.New("provider not found for model") // ErrProviderDisabled is returned when the provider is switched off ErrProviderDisabled = errors.New("provider is disabled") // ErrModelDisabled is returned when an admin override disables the requested model ErrModelDisabled = errors.New("model is disabled by administrator") // ErrEndpointNotSupported is returned when the provider or model does // not serve the requested endpoint (e.g. audio/transcriptions) ErrEndpointNotSupported = errors.New("endpoint not supported") // ErrTimeout marks upstream timeouts outside the ProviderError path // (e.g. transport-level deadlines). Prefer ProviderError with // ErrorTypeUpstream when an upstream response exists. ErrTimeout = errors.New("upstream timeout") // ErrRateLimited marks upstream rate limits outside the ProviderError // path. Prefer ProviderError with ErrorTypeRateLimit when an upstream // response exists. ErrRateLimited = errors.New("upstream rate limited") )
Standard sentinel errors
Functions ¶
func ErrorTypeForCode ¶ added in v0.1.2
ErrorTypeForCode maps a wire code to its OpenAI error type.
func MapUpstream ¶ added in v0.1.2
func MapUpstream(status int, code, errType, message string) *models.ProviderError
MapUpstream builds a ProviderError from an upstream HTTP status plus the structured code/type of the upstream error envelope. Code/type fallbacks run before the bare-status default so non-standard upstreams signalling quota/content/model state through 400 are classified correctly instead of collapsing into invalid_request. Message text never decides, except the quota wording handled one layer up on bare 429s.
func NewNotFoundError ¶
NewNotFoundError creates a NotFoundError
func NewValidationError ¶
NewValidationError creates a ValidationError
func ParseEnvelope ¶ added in v0.1.2
ParseEnvelope extracts code/type/message from an OpenAI-style error envelope: {"error":{"code","type","message"}}. Unknown shapes yield empty values and callers fall back to status-based mapping. Message text never decides the error type; MapUpstream owns that mapping.
func RetryAfterDelay ¶ added in v0.3.7
RetryAfterDelay reports how long the caller should wait before retrying: the ProviderError RetryAfter instant when it lies in the future, rounded up to whole seconds. Anything else reports false: the server offers no wait hint, and clients back off blindly. In practice only rate_limit and quota_exceeded carry RetryAfter; the contract forbids it elsewhere.
Types ¶
type APIError ¶ added in v0.1.2
APIError is the transport mapping of a domain error: HTTP status plus the wire code. Both API surfaces (OpenAI /v1 and dashboard) render from it.
func ToAPIError ¶ added in v0.1.2
ToAPIError maps any domain error to its wire representation. Single source of truth for status/code selection; no message-substring matching.
type NotFoundError ¶
NotFoundError wraps ErrNotFound with context about what was not found
func (*NotFoundError) Error ¶
func (e *NotFoundError) Error() string
func (*NotFoundError) Unwrap ¶
func (e *NotFoundError) Unwrap() error
type ValidationError ¶
ValidationError wraps ErrInvalidInput with details about what failed validation
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
func (*ValidationError) Unwrap ¶
func (e *ValidationError) Unwrap() error