Skip to main content

ferro_notifications/
error.rs

1//! Error types for the notification system.
2
3use thiserror::Error;
4
5/// Errors that can occur during notification dispatch.
6#[derive(Error, Debug)]
7pub enum Error {
8    /// Failed to send email notification.
9    #[error("mail error: {0}")]
10    Mail(String),
11
12    /// Failed to send Slack notification.
13    #[error("slack error: {0}")]
14    Slack(String),
15
16    /// Failed to store database notification.
17    #[error("database error: {0}")]
18    Database(String),
19
20    /// Channel not configured or available.
21    #[error("channel not available: {0}")]
22    ChannelNotAvailable(String),
23
24    /// Serialization error.
25    #[error("serialization error: {0}")]
26    Serialization(#[from] serde_json::Error),
27
28    /// Generic notification error.
29    #[error("{0}")]
30    Other(String),
31}
32
33impl Error {
34    /// Create a mail error.
35    pub fn mail(msg: impl Into<String>) -> Self {
36        Self::Mail(msg.into())
37    }
38
39    /// Create a slack error.
40    pub fn slack(msg: impl Into<String>) -> Self {
41        Self::Slack(msg.into())
42    }
43
44    /// Create a database error.
45    pub fn database(msg: impl Into<String>) -> Self {
46        Self::Database(msg.into())
47    }
48}