wechat_mp_core/error.rs
1//! SDK 错误类型
2
3use thiserror::Error;
4
5/// 小程序服务端 SDK 统一错误
6#[derive(Debug, Error)]
7pub enum MpError {
8 /// 配置错误
9 #[error("配置错误: {0}")]
10 Config(String),
11
12 /// HTTP 请求失败
13 #[error("HTTP 请求失败: {0}")]
14 Http(#[from] reqwest::Error),
15
16 /// 微信业务错误(errcode != 0)
17 #[error("微信接口错误 [{code}]: {message}")]
18 Api {
19 /// 微信 errcode
20 code: i64,
21 /// 错误描述
22 message: String,
23 },
24
25 /// JSON 序列化 / 反序列化失败
26 #[error("JSON 错误: {0}")]
27 Json(#[from] serde_json::Error),
28
29 /// 其他错误
30 #[error("{0}")]
31 Other(String),
32}
33
34/// Result 别名
35pub type Result<T> = std::result::Result<T, MpError>;