Skip to main content

weixin_agent/
error.rs

1//! Unified error types for the weixin-agent SDK.
2
3/// All errors produced by this SDK.
4#[derive(thiserror::Error, Debug)]
5#[non_exhaustive]
6pub enum Error {
7    /// HTTP transport error.
8    #[error("HTTP request failed: {0}")]
9    Http(#[from] reqwest::Error),
10
11    /// JSON serialization/deserialization error.
12    #[error("JSON error: {0}")]
13    Json(#[from] serde_json::Error),
14
15    /// File I/O error.
16    #[error("I/O error: {0}")]
17    Io(#[from] std::io::Error),
18
19    /// Server returned a non-zero error code.
20    #[error("API error: errcode={errcode}, errmsg={errmsg}")]
21    Api {
22        /// Server error code.
23        errcode: i32,
24        /// Server error message.
25        errmsg: String,
26    },
27
28    /// Session expired; the monitor will pause for one hour.
29    #[error("Session expired for account, paused until cooldown")]
30    SessionExpired,
31
32    /// CDN upload failure.
33    #[error("CDN upload failed: {0}")]
34    CdnUpload(String),
35
36    /// AES encryption/decryption failure.
37    #[error("Encryption error: {0}")]
38    Crypto(String),
39
40    /// Invalid configuration.
41    #[error("Configuration error: {0}")]
42    Config(String),
43
44    /// Operation timed out.
45    #[error("Timeout: {0}")]
46    Timeout(String),
47}
48
49/// Convenience alias used throughout the SDK.
50pub type Result<T> = std::result::Result<T, Error>;