Skip to main content

signer_remote/
error.rs

1//! 错误类型定义
2use thiserror::Error;
3use reqwest::Error as ReqwestError;
4use serde_json::Error as SerdeJsonError;
5use signer_core::SignerError;
6
7/// 远程服务错误类型
8#[derive(Error, Debug)]
9pub enum RemoteError {
10    /// IO 错误
11    #[error("IO error: {0}")]
12    Io(#[from] std::io::Error),
13    
14    /// JSON 序列化/反序列化错误
15    #[error("JSON error: {source}. Reason: {reason}. Input: {input}")]
16    Json {
17        #[source]
18        source: SerdeJsonError,
19        reason: String,
20        input: String,
21    },
22    
23    /// 网络请求错误
24    #[error("Network error: {0}")]
25    Network(#[from] ReqwestError),
26    
27    /// Signer 相关错误
28    #[error("Signer error: {0}")]
29    Signer(#[from] SignerError),
30    
31    /// 配置错误
32    #[error("Invalid configuration: {0}")]
33    Config(String),
34    
35    /// 内部错误
36    #[error("Internal error: {0}")]
37    Internal(String),
38
39    /// 网络连接或通信错误 (为 SignerTransferClient 添加)
40    #[error("Network connection error: {0}")]
41    NetworkError(String),
42
43    /// 无效操作错误 (为 SignerTransferClient 添加)
44    #[error("Invalid operation: {0}")]
45    InvalidOperation(String),
46
47    /// 序列化错误 (为 SignerTransferClient 添加)
48    #[error("Serialization error: {0}")]
49    SerializationError(String),
50}
51
52/// 统一的结果类型
53pub type RemoteResult<T> = std::result::Result<T, RemoteError>;