1use crate::ResponseMetadata;
2use std::time::Duration;
3
4#[derive(Debug, thiserror::Error)]
6pub enum SlackError {
7 #[error("slack api error: {}", .0.error)]
9 Api(Box<SlackApiError>),
10 #[error("rate limited by slack (retry after {retry_after:?})")]
12 RateLimited { retry_after: Option<Duration> },
13 #[error("unexpected http status {status}")]
15 Http { status: u16, body: String },
16 #[error("transport error: {0}")]
18 Transport(#[from] reqwest::Error),
19 #[error("failed to decode response: {source}")]
21 Decode {
22 source: serde_json::Error,
23 body: String,
24 },
25 #[error("failed to encode request: {0}")]
27 Encode(String),
28 #[error("response is missing {0}")]
30 MissingField(&'static str),
31 #[error("background task failed: {0}")]
33 Task(String),
34}
35
36#[derive(Debug, Clone, PartialEq)]
38pub struct SlackApiError {
39 pub error: String,
41 pub warning: Option<String>,
43 pub response_metadata: Option<ResponseMetadata>,
45}
46
47impl SlackError {
48 pub fn api_error(&self) -> Option<&str> {
50 match self {
51 SlackError::Api(e) => Some(e.error.as_str()),
52 _ => None,
53 }
54 }
55}