errors

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package errors defines standard error types used across llm-router services.

Index

Constants

This section is empty.

Variables

View Source
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 is returned for authentication failures
	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

func ErrorTypeForCode(code string) string

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

func NewNotFoundError(resource, id string) error

NewNotFoundError creates a NotFoundError

func NewValidationError

func NewValidationError(field, message string) error

NewValidationError creates a ValidationError

func ParseEnvelope added in v0.1.2

func ParseEnvelope(body string) (code, errType, message string)

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.

Types

type APIError added in v0.1.2

type APIError struct {
	Status int
	Code   string
}

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

func ToAPIError(err error) APIError

ToAPIError maps any domain error to its wire representation. Single source of truth for status/code selection; no message-substring matching.

type NotFoundError

type NotFoundError struct {
	Resource string
	ID       string
}

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

type ValidationError struct {
	Field   string
	Message string
}

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

Jump to

Keyboard shortcuts

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