Skip to main content

ErrorTrait

Trait ErrorTrait 

Source
pub trait ErrorTrait:
    Error
    + Send
    + Sync
    + 'static {
Show 19 methods // Required methods fn severity(&self) -> ErrorSeverity; fn is_retryable(&self) -> bool; fn retry_delay(&self, attempt: u32) -> Option<Duration>; fn user_message(&self) -> Option<&str>; fn context(&self) -> &ErrorContext; fn error_type(&self) -> ErrorType; // Provided methods fn error_code(&self) -> Option<&str> { ... } fn is_user_error(&self) -> bool { ... } fn is_system_error(&self) -> bool { ... } fn is_network_error(&self) -> bool { ... } fn is_auth_error(&self) -> bool { ... } fn is_validation_error(&self) -> bool { ... } fn is_timeout_error(&self) -> bool { ... } fn is_rate_limited(&self) -> bool { ... } fn is_config_error(&self) -> bool { ... } fn is_serialization_error(&self) -> bool { ... } fn is_business_error(&self) -> bool { ... } fn is_api_error(&self) -> bool { ... } fn is_service_unavailable_error(&self) -> bool { ... }
}
Expand description

核心错误特征

所有错误类型都应该实现此特征,提供统一的错误处理接口

Required Methods§

Source

fn severity(&self) -> ErrorSeverity

获取错误严重程度

Source

fn is_retryable(&self) -> bool

判断是否可重试

Source

fn retry_delay(&self, attempt: u32) -> Option<Duration>

获取建议的重试延迟

Source

fn user_message(&self) -> Option<&str>

获取用户友好的错误消息

Source

fn context(&self) -> &ErrorContext

获取错误上下文信息

Source

fn error_type(&self) -> ErrorType

判断错误类型

Provided Methods§

Source

fn error_code(&self) -> Option<&str>

获取错误代码(如果有)

Source

fn is_user_error(&self) -> bool

判断是否为用户错误

Source

fn is_system_error(&self) -> bool

判断是否为系统错误

Source

fn is_network_error(&self) -> bool

判断是否为网络错误

Source

fn is_auth_error(&self) -> bool

判断是否为认证错误

Source

fn is_validation_error(&self) -> bool

判断是否为验证错误

Source

fn is_timeout_error(&self) -> bool

判断是否为超时错误

Source

fn is_rate_limited(&self) -> bool

判断是否为限流错误

Source

fn is_config_error(&self) -> bool

判断是否为配置错误

Source

fn is_serialization_error(&self) -> bool

判断是否为序列化错误

Source

fn is_business_error(&self) -> bool

判断是否为业务错误

Source

fn is_api_error(&self) -> bool

判断是否为API错误

Source

fn is_service_unavailable_error(&self) -> bool

判断是否为服务不可用错误

Implementors§