Skip to main content

lark_webhook_notify/
error.rs

1#[derive(thiserror::Error, Debug)]
2pub enum LarkWebhookError {
3    #[error("HTTP error: {0}")]
4    Http(#[from] reqwest::Error),
5    #[error("Lark API error: code {code} - {message}")]
6    ApiError { code: i64, message: String },
7    #[error("Configuration error: {0}")]
8    Config(String),
9    #[error("JSON error: {0}")]
10    Json(#[from] serde_json::Error),
11}
12
13pub type Result<T> = std::result::Result<T, LarkWebhookError>;
14
15#[cfg(test)]
16mod tests {
17    use super::*;
18
19    #[test]
20    fn test_config_error_display() {
21        let e = LarkWebhookError::Config("missing url".to_owned());
22        assert_eq!(e.to_string(), "Configuration error: missing url");
23    }
24
25    #[test]
26    fn test_api_error_display() {
27        let e = LarkWebhookError::ApiError {
28            code: 99,
29            message: "bad request".to_owned(),
30        };
31        assert_eq!(e.to_string(), "Lark API error: code 99 - bad request");
32    }
33}