use crate::ResponseMetadata;
use std::time::Duration;
#[derive(Debug, thiserror::Error)]
pub enum SlackError {
#[error("slack api error: {}", .0.error)]
Api(Box<SlackApiError>),
#[error("rate limited by slack (retry after {retry_after:?})")]
RateLimited { retry_after: Option<Duration> },
#[error("unexpected http status {status}")]
Http { status: u16, body: String },
#[error("transport error: {0}")]
Transport(#[from] reqwest::Error),
#[error("failed to decode response: {source}")]
Decode {
source: serde_json::Error,
body: String,
},
#[error("failed to encode request: {0}")]
Encode(String),
#[error("response is missing {0}")]
MissingField(&'static str),
#[error("background task failed: {0}")]
Task(String),
}
#[derive(Debug, Clone, PartialEq)]
pub struct SlackApiError {
pub error: String,
pub warning: Option<String>,
pub response_metadata: Option<ResponseMetadata>,
}
impl SlackError {
pub fn api_error(&self) -> Option<&str> {
match self {
SlackError::Api(e) => Some(e.error.as_str()),
_ => None,
}
}
}