wechat_error/
lib.rs

1#![deny(missing_debug_implementations, missing_copy_implementations)]
2#![warn(missing_docs, rustdoc::missing_crate_level_docs)]
3#![doc = include_str!("../readme.md")]
4#![doc(html_logo_url = "https://raw.githubusercontent.com/oovm/shape-rs/dev/projects/images/Trapezohedron.svg")]
5#![doc(html_favicon_url = "https://raw.githubusercontent.com/oovm/shape-rs/dev/projects/images/Trapezohedron.svg")]
6
7mod convert;
8
9mod display;
10
11/// 常用第三方库
12pub mod party_3rd {
13    #[cfg(feature = "chrono")]
14    pub use chrono;
15    #[cfg(feature = "hmac")]
16    pub use hmac::{Hmac, Mac};
17    #[cfg(feature = "lettre")]
18    pub use lettre;
19    #[cfg(feature = "reqwest")]
20    pub use reqwest;
21}
22
23/// The result type of this crate.
24pub type Result<T> = std::result::Result<T, AliError>;
25
26/// A boxed error kind, wrapping an [AliErrorKind].
27#[derive(Clone)]
28pub struct AliError {
29    kind: Box<AliErrorKind>,
30}
31
32/// 枚举定义阿里云服务中可能发生的错误类型
33#[derive(Debug, Clone)]
34pub enum AliErrorKind {
35    /// 服务器错误
36    ServiceError {
37        /// 错误信息
38        message: String,
39    },
40    /// 网络错误
41    NetworkError {
42        /// 错误信息
43        message: String,
44    },
45    /// 编码错误
46    EncoderError {
47        /// 错误编码格式
48        format: String,
49        /// 错误信息
50        message: String,
51    },
52    /// 解码错误
53    DecoderError {
54        /// 错误解码格式
55        format: String,
56        /// 错误信息
57        message: String,
58    },
59    /// 自定义错误
60    CustomError {
61        /// 错误信息
62        message: String,
63    },
64    /// 未知错误
65    UnknownError,
66}
67
68impl AliError {
69    /// 创建一个网络错误
70    pub fn network_error(message: impl Into<String>) -> Self {
71        AliErrorKind::NetworkError { message: message.into() }.into()
72    }
73    /// 创建一个自定义错误
74    pub fn custom_error(message: impl Into<String>) -> Self {
75        AliError { kind: Box::new(AliErrorKind::CustomError { message: message.into() }) }
76    }
77}