error-handling
LiteLLM-RS Error Handling Architecture. Covers two-tier error hierarchy, ProviderError factory methods, HTTP status mapping, retry logic, and error context…
от majiayu000★ 124 звезды на GitHub
Установить error-handling в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Error Handling Architecture Guide
Two-Tier Error Hierarchy
LiteLLM-RS uses a two-tier error architecture spanning its provider catalog:
┌────────────────────────────────────────────────────────┐
│ Gateway Layer │
│ LiteLLMError (core/types/errors/litellm.rs) │
│ - Type alias for GatewayError │
│ (src/utils/error/gateway_error/types.rs) │
│ - 18 variants for gateway-level errors │
└────────────────────────────────────────────────────────┘
↓
┌────────────────────────────────────────────────────────┐
│ Provider Layer │
│ ProviderError │
│ (src/core/providers/unified_provider_error.rs; │
│ exported as core::providers::ProviderError) │
│ - 24 variants for provider-specific errors │
│ - Each variant includes provider: &'static str │
│ - Rich factory methods for error creation │
└────────────────────────────────────────────────────────┘
HTTP Status Mapping
Standard Mapping Pattern
Most providers share one canonical status-to-error mapping,
default_http_error_mapper in src/core/providers/unified_provider_http_mapping.rs:
pub fn default_http_error_mapper(
provider: &'static str,
status_code: u16,
response_body: &str,
) -> ProviderError {
match status_code {
400 => {
let message = parse_error_message_from_body(response_body)
.unwrap_or_else(|| response_body.to_string());
ProviderError::invalid_request(provider, message)
}
401 => ProviderError::authentication(provider, "Invalid API key"),
403 => ProviderError::authentication(provider, "Permission denied"),
404 => ProviderError::model_not_found(provider, "Model not found"),
429 => {
let retry_after =
crate::core::providers::shared::parse_retry_after_from_body(response_body);
ProviderError::rate_limit(provider, retry_after)
}
500..=599 => ProviderError::api_error(provider, status_code, response_body),
_ => ProviderError::api_error(provider, status_code, response_body),
}
}
Providers needing extra special cases call extended_http_error_mapper
(same file), which additionally maps 402 to quota_exceeded, 408/504 to
timeout, 413 to context_length_exceeded, and 502/503 to
provider_unavailable.
ErrorMapper Trait
// src/core/traits/error_mapper/trait_def.rs
pub trait ErrorMapper<E>: Send + Sync + 'static
where
E: ProviderErrorTrait,
{
// Required: map HTTP status + body to the provider's error type
fn map_http_error(&self, status_code: u16, response_body: &str) -> E;
// Default implementations
fn map_json_error(&self, error_response: &serde_json::Value) -> E;
fn map_network_error(&self, error: &dyn std::error::Error) -> E;
fn map_parsing_error(&self, error: &dyn std::error::Error) -> E;
fn map_timeout_error(&self, timeout_duration: std::time::Duration) -> E;
}
GenericErrorMapper (src/core/traits/error_mapper/types.rs, re-exported as
DefaultErrorMapper) implements ErrorMapper<E> for any E: ProviderErrorTrait:
impl<E> ErrorMapper<E> for GenericErrorMapper
where
E: ProviderErrorTrait,
{
fn map_http_error(&self, status_code: u16, response_body: &str) -> E {
match status_code {
400 => E::network_error("Bad Request: Invalid parameters"),
401 => E::authentication_failed("Authentication failed: Invalid credentials"),
403 => E::authentication_failed("Permission denied: Insufficient permissions"),
404 => E::not_supported("Resource not found"),
408 => E::network_error("Request timeout"),
429 => E::rate_limited(None),
500 => E::network_error("Internal server error"),
502 => E::network_error("Bad gateway: Upstream server error"),
503 => E::network_error("Service unavailable: Server overloaded"),
504 => E::network_error("Gateway timeout: Upstream timeout"),
_ => E::network_error(/* "HTTP Error {status}: {body or default}" */),
}
}
}
Best Practices
1. Always Use Factory Methods
// Good
ProviderError::authentication(PROVIDER_NAME, "Invalid API key")
// Bad - verbose and error-prone
ProviderError::Authentication {
provider: PROVIDER_NAME,
message: "Invalid API key".to_string(),
}
2. Include Provider Name
// Good - error clearly identifies source
ProviderError::network("openai", "Connection refused")
// Bad - unclear which provider failed
ProviderError::network("unknown", "Connection refused")
3. Preserve Error Context
// Good - execute_request already returns a classified ProviderError
let response = s
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- reference/error-context-preservation.md
- reference/factory-methods.md
- reference/litellm-error-gateway.md
- reference/provider-error-variants.md
- reference/retry-logic.md
FAQ
Что делает скилл error-handling?
LiteLLM-RS Error Handling Architecture. Covers two-tier error hierarchy, ProviderError factory methods, HTTP status mapping, retry logic, and error context preservation. Use when designing error types or enums, creating ProviderError instances via factory methods, mapping HTTP statuses to typed errors, deciding retryability and backoff, or preserving error context.
Как установить скилл error-handling?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл error-handling запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
AnthropicToolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
access
AnthropicManage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
configure
AnthropicSet up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
access
AnthropicManage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…