acton_htmx/email/
error.rs

1//! Email error types
2
3use thiserror::Error;
4
5/// Errors that can occur when working with emails
6#[derive(Debug, Error)]
7pub enum EmailError {
8    /// Email has no recipients
9    #[error("email must have at least one recipient")]
10    NoRecipients,
11
12    /// Email has no sender
13    #[error("email must have a from address")]
14    NoSender,
15
16    /// Email has no subject
17    #[error("email must have a subject")]
18    NoSubject,
19
20    /// Email has no body content
21    #[error("email must have either text or HTML content")]
22    NoContent,
23
24    /// Invalid email address format
25    #[error("invalid email address: {0}")]
26    InvalidAddress(String),
27
28    /// Template rendering error
29    #[error("failed to render email template: {0}")]
30    TemplateError(#[from] askama::Error),
31
32    /// SMTP transport error
33    #[error("SMTP error: {0}")]
34    SmtpError(String),
35
36    /// AWS SES error
37    #[error("AWS SES error: {0}")]
38    AwsSesError(String),
39
40    /// Email configuration error
41    #[error("email configuration error: {0}")]
42    ConfigError(String),
43
44    /// I/O error
45    #[error("I/O error: {0}")]
46    IoError(#[from] std::io::Error),
47
48    /// Serialization error
49    #[error("serialization error: {0}")]
50    SerializationError(#[from] serde_json::Error),
51}
52
53impl EmailError {
54    /// Create an SMTP error from a string message
55    #[must_use]
56    pub fn smtp<T: Into<String>>(msg: T) -> Self {
57        Self::SmtpError(msg.into())
58    }
59
60    /// Create an AWS SES error from a string message
61    #[must_use]
62    pub fn aws_ses<T: Into<String>>(msg: T) -> Self {
63        Self::AwsSesError(msg.into())
64    }
65
66    /// Create a configuration error from a string message
67    #[must_use]
68    pub fn config<T: Into<String>>(msg: T) -> Self {
69        Self::ConfigError(msg.into())
70    }
71}