#[non_exhaustive]pub enum LiterLlmError {
Show 21 variants
Authentication {
message: String,
status: u16,
},
RateLimited {
message: String,
retry_after: Option<Duration>,
},
BadRequest {
message: String,
status: u16,
},
ContextWindowExceeded {
message: String,
},
ContentPolicy {
message: String,
},
NotFound {
message: String,
},
ServerError {
message: String,
status: u16,
},
ServiceUnavailable {
message: String,
status: u16,
retry_after: Option<Duration>,
},
Timeout,
Network {
message: String,
},
Streaming {
message: String,
},
EndpointNotSupported {
endpoint: String,
provider: String,
},
InvalidHeader {
name: String,
reason: String,
},
Serialization(Error),
BudgetExceeded {
message: String,
model: Option<String>,
},
HookRejected {
message: String,
},
InternalError {
message: String,
},
OutboundForbidden {
url: String,
reason: String,
},
IdempotencyConflict {
key: String,
},
IdempotencyInFlight {
key: String,
},
ProviderQuotaExceeded {
message: String,
status: u16,
},
}Expand description
All errors that can occur when using liter-llm.
Each variant carries a stable numeric error_code (>= 100) that bindings expose
across the FFI boundary. Codes are append-only: never renumber or reuse a code.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Authentication
status preserves the exact HTTP status code received (401 or 403).
RateLimited
BadRequest
status preserves the exact HTTP status code received (400, 405, 413, 422, …).
ContextWindowExceeded
ContentPolicy
NotFound
ServerError
status preserves the exact HTTP status code received (500, or other 5xx not covered
by ServiceUnavailable).
status preserves the exact HTTP status code received (502, 503, or 504).
Timeout
Network
Streaming
A catch-all for errors that occur during streaming response processing.
This variant covers multiple sub-conditions including UTF-8 decoding
failures, CRC/checksum mismatches (AWS EventStream), JSON parse errors
in individual SSE chunks, and buffer overflow conditions. The message
field contains a human-readable description of the specific failure.
EndpointNotSupported
InvalidHeader
Serialization(Error)
BudgetExceeded
HookRejected
InternalError
An internal logic error (e.g. unexpected Tower response variant).
This should never surface in normal operation — if it does, it indicates a bug in the library.
OutboundForbidden
An outbound request was blocked by the active crate::provider::OutboundPolicy.
Returned when register_custom_provider is called with a base_url that
violates the policy (e.g. a private-range IP under DenyPrivate), or when
the per-connection DNS resolver detects a forbidden address at connect time.
IdempotencyConflict
A different request body was submitted for an existing Idempotency-Key.
Per the OpenAI Idempotency-Key convention, once a key is used with a
particular request body, subsequent requests using the same key must carry
an identical body. A body mismatch is a hard error (not retryable).
HTTP equivalent: 409 Conflict.
IdempotencyInFlight
The same Idempotency-Key is already in-flight (another request with the
same key is currently being processed).
The caller should wait briefly and retry. The response is not yet available, and this request has been short-circuited to avoid running the operation twice.
HTTP equivalent: 409 Conflict (retryable after a brief delay).
ProviderQuotaExceeded
The upstream provider rejected the request because the account quota is exhausted.
Implementations§
Source§impl LiterLlmError
impl LiterLlmError
Sourcepub fn status_code(&self) -> u16
pub fn status_code(&self) -> u16
Returns the canonical HTTP status code associated with this error.
Maps error variants to their originating HTTP status code as set by
the private from_status constructor. Used by e2e assertions that check
error.status_code against the expected HTTP status.
Sourcepub fn retry_after(&self) -> Option<Duration>
pub fn retry_after(&self) -> Option<Duration>
Returns the server-advertised retry delay, when the error carries one.
Parsed from the upstream Retry-After header on a 429. Exposed as an
accessor alongside Self::status_code and Self::error_type so the
generated bindings can surface it: the value reached the Rust core but
stopped there, leaving every binding consumer to re-derive its own
backoff from nothing more than the status code. ~keep
Sourcepub fn is_transient(&self) -> bool
pub fn is_transient(&self) -> bool
Returns true for errors that are worth retrying on a different service
or deployment (transient failures).
Used by [crate::tower::fallback::FallbackService] and
[crate::tower::router::Router] to decide whether to route to an
alternative endpoint.
Sourcepub fn error_type(&self) -> &'static str
pub fn error_type(&self) -> &'static str
Return the OpenTelemetry error.type string for this error variant.
Used by the tracing middleware to record the error.type span attribute
on failed requests per the GenAI semantic conventions.
Trait Implementations§
Source§impl Debug for LiterLlmError
impl Debug for LiterLlmError
Source§impl Display for LiterLlmError
impl Display for LiterLlmError
Source§impl Error for LiterLlmError
impl Error for LiterLlmError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl From<Error> for LiterLlmError
impl From<Error> for LiterLlmError
Source§impl From<Error> for LiterLlmError
Available on crate features native-http or wasm-http only.
impl From<Error> for LiterLlmError
native-http or wasm-http only.