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    /// Bot token is stale; the poll loop has entered its cooldown window.
29    ///
30    /// Only long polling is paused — outbound calls are not blocked by the SDK.
31    #[error("bot token is stale (errcode -14), polling paused for cooldown")]
32    TokenStale,
33
34    /// Deprecated: use [`Error::TokenStale`].
35    #[deprecated(since = "0.3.0", note = "use Error::TokenStale")]
36    #[error("session expired for account, paused until cooldown")]
37    SessionExpired,
38
39    /// CDN upload failure.
40    #[error("CDN upload failed: {0}")]
41    CdnUpload(String),
42
43    /// AES encryption/decryption failure.
44    #[error("Encryption error: {0}")]
45    Crypto(String),
46
47    /// Invalid configuration.
48    #[error("Configuration error: {0}")]
49    Config(String),
50
51    /// Operation timed out.
52    #[error("Timeout: {0}")]
53    Timeout(String),
54}
55
56/// Convenience alias used throughout the SDK.
57pub type Result<T> = std::result::Result<T, Error>;