Skip to main content

fraiseql_error/
notification.rs

1use std::time::Duration;
2
3#[derive(Debug, thiserror::Error)]
4pub enum NotificationError {
5    #[error("Configuration error: {message}")]
6    Configuration { message: String },
7
8    #[error("Provider error: {provider} - {message}")]
9    Provider { provider: String, message: String },
10
11    #[error("Provider unavailable: {provider}")]
12    ProviderUnavailable {
13        provider:    String,
14        retry_after: Option<Duration>,
15    },
16
17    #[error("Invalid input: {message}")]
18    InvalidInput { message: String },
19
20    #[error("Template error: {message}")]
21    Template { message: String },
22
23    #[error("Rate limited by provider: retry after {seconds} seconds")]
24    ProviderRateLimited { provider: String, seconds: u64 },
25
26    #[error("Circuit breaker open for provider: {provider}")]
27    CircuitOpen {
28        provider:    String,
29        retry_after: Duration,
30    },
31
32    #[error("Timeout sending notification")]
33    Timeout,
34}
35
36impl NotificationError {
37    pub const fn error_code(&self) -> &'static str {
38        match self {
39            Self::Configuration { .. } => "notification_config_error",
40            Self::Provider { .. } => "notification_provider_error",
41            Self::ProviderUnavailable { .. } => "notification_provider_unavailable",
42            Self::InvalidInput { .. } => "notification_invalid_input",
43            Self::Template { .. } => "notification_template_error",
44            Self::ProviderRateLimited { .. } => "notification_rate_limited",
45            Self::CircuitOpen { .. } => "notification_circuit_open",
46            Self::Timeout => "notification_timeout",
47        }
48    }
49}