Skip to main content

SecurityError

Type Alias SecurityError 

Source
pub type SecurityError = CoreError;
Expand description

安全服务错误类型 - 完全基于 CoreError

Aliased Type§

pub enum SecurityError {
    Network(Box<NetworkError>),
    Authentication {
        message: String,
        code: ErrorCode,
        ctx: Box<ErrorContext>,
    },
    Api(Box<ApiError>),
    Validation {
        field: Cow<'static, str>,
        message: String,
        code: ErrorCode,
        ctx: Box<ErrorContext>,
    },
    Configuration {
        message: String,
        code: ErrorCode,
        ctx: Box<ErrorContext>,
    },
    Serialization {
        message: String,
        source: Option<Box<dyn Error + Send + Sync>>,
        code: ErrorCode,
        ctx: Box<ErrorContext>,
    },
    Business {
        code: ErrorCode,
        message: String,
        ctx: Box<ErrorContext>,
    },
    Timeout {
        duration: Duration,
        operation: Option<String>,
        ctx: Box<ErrorContext>,
    },
    RateLimit {
        limit: u32,
        window: Duration,
        reset_after: Option<Duration>,
        code: ErrorCode,
        ctx: Box<ErrorContext>,
    },
    ServiceUnavailable {
        service: Cow<'static, str>,
        retry_after: Option<Duration>,
        code: ErrorCode,
        ctx: Box<ErrorContext>,
    },
    ResponseTooLarge {
        limit: u64,
        actual: u64,
        ctx: Box<ErrorContext>,
    },
    Internal {
        code: ErrorCode,
        message: String,
        source: Option<Box<dyn Error + Send + Sync>>,
        ctx: Box<ErrorContext>,
    },
}

Variants§

§

Network(Box<NetworkError>)

网络错误

§

Authentication

认证错误

Fields

§message: String

错误消息

§code: ErrorCode

错误码

§ctx: Box<ErrorContext>

错误上下文

§

Api(Box<ApiError>)

API 错误

§

Validation

验证错误

Fields

§field: Cow<'static, str>

字段名

§message: String

错误消息

§code: ErrorCode

错误码

§ctx: Box<ErrorContext>

错误上下文

§

Configuration

配置错误

Fields

§message: String

错误消息

§code: ErrorCode

错误码

§ctx: Box<ErrorContext>

错误上下文

§

Serialization

序列化错误

Fields

§message: String

错误消息

§source: Option<Box<dyn Error + Send + Sync>>

源错误

§code: ErrorCode

错误码

§ctx: Box<ErrorContext>

错误上下文

§

Business

业务错误

Fields

§code: ErrorCode

错误码

§message: String

错误消息

§ctx: Box<ErrorContext>

错误上下文

§

Timeout

超时错误

Fields

§duration: Duration

超时时长

§operation: Option<String>

操作名

§ctx: Box<ErrorContext>

错误上下文

§

RateLimit

限流错误

Fields

§limit: u32

限制次数

§window: Duration

时间窗口

§reset_after: Option<Duration>

重置时间

§code: ErrorCode

错误码

§ctx: Box<ErrorContext>

错误上下文

§

ServiceUnavailable

服务不可用错误

Fields

§service: Cow<'static, str>

服务名

§retry_after: Option<Duration>

重试等待时间

§code: ErrorCode

错误码

§ctx: Box<ErrorContext>

错误上下文

§

ResponseTooLarge

响应体大小超过限制

Fields

§limit: u64

配置的大小限制

§actual: u64

实际大小(已知时),否则为 0

§ctx: Box<ErrorContext>

错误上下文

§

Internal

内部错误

Fields

§code: ErrorCode

错误码

§message: String

错误消息

§source: Option<Box<dyn Error + Send + Sync>>

源错误

§ctx: Box<ErrorContext>

错误上下文

Trait Implementations§

Source§

impl SecurityErrorExt for SecurityError

Source§

fn is_device_error(&self) -> bool

检查是否为设备相关错误
Source§

fn is_permission_error(&self) -> bool

检查是否为权限相关错误
Source§

fn is_compliance_error(&self) -> bool

检查是否为合规相关错误
Source§

fn is_authentication_error(&self) -> bool

检查是否为认证相关错误
Source§

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

获取安全操作类型
Source§

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

获取受影响的资源ID
Source§

fn to_security_event(&self) -> SecurityEvent

生成安全事件报告