1use hookburn_core::CoreError;
3use thiserror::Error;
4
5#[derive(Error, Debug)]
10pub enum SlackError {
11 #[error("HTTP request failed: {0}")]
15 Http(#[from] reqwest::Error),
16
17 #[error("Message must have text content")]
21 EmptyMessage,
22
23 #[error("Rate limited by Slack: retry after {retry_after_ms}ms")]
28 RateLimited {
29 retry_after_ms: u64,
31 },
32
33 #[error("Slack API error (HTTP {status}): {message}")]
37 ApiError {
38 status: u16,
40 message: String,
42 },
43
44 #[error("JSON serialization failed: {0}")]
49 Json(#[from] serde_json::Error),
50
51 #[error("Invalid webhook URL: {reason}")]
55 InvalidUrl {
56 reason: String,
58 },
59}
60
61impl From<CoreError> for SlackError {
62 fn from(err: CoreError) -> Self {
63 match err {
64 CoreError::Network(e) => SlackError::Http(e),
65 CoreError::Json(e) => SlackError::Json(e),
66 CoreError::ServiceNotFound(s) => {
67 SlackError::ApiError { status: 404, message: format!("Service not found: {}", s) }
68 }
69 CoreError::ServiceCreationFailed(s) => SlackError::ApiError {
70 status: 500,
71 message: format!("Service creation failed: {}", s),
72 },
73 CoreError::ServiceError(s) => SlackError::ApiError { status: 500, message: s },
74 CoreError::InvalidServiceConfig(s) => SlackError::InvalidUrl { reason: s },
75 CoreError::MessageConversionFailed(s) => SlackError::ApiError {
76 status: 400,
77 message: format!("Message conversion failed: {}", s),
78 },
79 CoreError::RateLimitExceeded { retry_after } => {
80 SlackError::RateLimited { retry_after_ms: retry_after.as_millis() as u64 }
81 }
82 CoreError::ServiceReturnedError { service, status_code, message } => {
83 SlackError::ApiError {
84 status: status_code.unwrap_or(500),
85 message: format!("{} error: {}", service, message),
86 }
87 }
88 CoreError::RetryExhausted(s) => {
89 SlackError::ApiError { status: 500, message: format!("Retry exhausted: {}", s) }
90 }
91 _ => SlackError::ApiError {
93 status: 500,
94 message: format!("Unexpected core error: {}", err),
95 },
96 }
97 }
98}