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§
Sourcefn severity(&self) -> ErrorSeverity
fn severity(&self) -> ErrorSeverity
获取错误严重程度
Sourcefn is_retryable(&self) -> bool
fn is_retryable(&self) -> bool
判断是否可重试
Sourcefn retry_delay(&self, attempt: u32) -> Option<Duration>
fn retry_delay(&self, attempt: u32) -> Option<Duration>
获取建议的重试延迟
Sourcefn user_message(&self) -> Option<&str>
fn user_message(&self) -> Option<&str>
获取用户友好的错误消息
Sourcefn context(&self) -> &ErrorContext
fn context(&self) -> &ErrorContext
获取错误上下文信息
Sourcefn error_type(&self) -> ErrorType
fn error_type(&self) -> ErrorType
判断错误类型
Provided Methods§
Sourcefn error_code(&self) -> Option<&str>
fn error_code(&self) -> Option<&str>
获取错误代码(如果有)
Sourcefn is_user_error(&self) -> bool
fn is_user_error(&self) -> bool
判断是否为用户错误
Sourcefn is_system_error(&self) -> bool
fn is_system_error(&self) -> bool
判断是否为系统错误
Sourcefn is_network_error(&self) -> bool
fn is_network_error(&self) -> bool
判断是否为网络错误
Sourcefn is_auth_error(&self) -> bool
fn is_auth_error(&self) -> bool
判断是否为认证错误
Sourcefn is_validation_error(&self) -> bool
fn is_validation_error(&self) -> bool
判断是否为验证错误
Sourcefn is_timeout_error(&self) -> bool
fn is_timeout_error(&self) -> bool
判断是否为超时错误
Sourcefn is_rate_limited(&self) -> bool
fn is_rate_limited(&self) -> bool
判断是否为限流错误
Sourcefn is_config_error(&self) -> bool
fn is_config_error(&self) -> bool
判断是否为配置错误
Sourcefn is_serialization_error(&self) -> bool
fn is_serialization_error(&self) -> bool
判断是否为序列化错误
Sourcefn is_business_error(&self) -> bool
fn is_business_error(&self) -> bool
判断是否为业务错误
Sourcefn is_api_error(&self) -> bool
fn is_api_error(&self) -> bool
判断是否为API错误
判断是否为服务不可用错误