Documentation
¶
Overview ¶
Package errors defines standard error types used across llm-router services.
Index ¶
- Constants
- Variables
- func AnthropicErrorType(code string) string
- func AnthropicStatus(code string, status int) int
- func ErrorTypeForCode(code string) string
- func NewNotFoundError(resource, id string) error
- func NewValidationError(field, message string) error
- type APIError
- type NotFoundError
- type ValidationError
Constants ¶
const ( CodeInvalidRequest = "invalid_request_error" CodeNotFound = "not_found" CodeProviderNotFound = "provider_not_found" CodeModelNotFound = "model_not_found" CodeEndpointUnsupported = "endpoint_not_supported" CodeNoCredential = "no_credential" CodeProviderDisabled = "provider_disabled" CodeModelNotAllowed = "model_not_allowed" CodeProviderNotAllowed = "provider_not_allowed" CodeCredentialNotAllow = "credential_not_allowed" CodeAuthError = "auth_error" CodeMissingToken = "missing_token" CodeInvalidToken = "invalid_token" CodePaymentRequired = "payment_required" CodeRateLimit = "rate_limit" CodeQuotaExceeded = "quota_exceeded" CodeOverloaded = "overloaded" CodeTimeout = "timeout" CodeTransportError = "transport_error" CodeUpstreamError = "upstream_error" CodeStructuralFault = "structural_fault" CodeServerError = "server_error" CodeInternalError = "internal_error" )
Wire error codes. Single source of truth for status/code strings rendered on both API surfaces.
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 AnthropicErrorType ¶ added in v0.3.8
AnthropicErrorType maps a wire code to its Anthropic error type. Single source of truth for the negotiated {type:error,error:{type,message}} envelope served on Anthropic-style requests.
func AnthropicStatus ¶ added in v0.3.8
AnthropicStatus maps a wire status to the Anthropic HTTP status: rate limits surface as 429 and congestion as 529; everything else keeps the shared status.
func ErrorTypeForCode ¶ added in v0.1.2
ErrorTypeForCode maps a wire code to its OpenAI error type.
func NewNotFoundError ¶
NewNotFoundError creates a NotFoundError
func NewValidationError ¶
NewValidationError creates a ValidationError
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. ProviderError carries its own status and code: the plugin already produced the terminal OpenAI-shaped error, so the router renders it verbatim after sanitizing the status into range.
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