acton_htmx/email/
error.rs1use thiserror::Error;
4
5#[derive(Debug, Error)]
7pub enum EmailError {
8 #[error("email must have at least one recipient")]
10 NoRecipients,
11
12 #[error("email must have a from address")]
14 NoSender,
15
16 #[error("email must have a subject")]
18 NoSubject,
19
20 #[error("email must have either text or HTML content")]
22 NoContent,
23
24 #[error("invalid email address: {0}")]
26 InvalidAddress(String),
27
28 #[error("failed to render email template: {0}")]
30 TemplateError(#[from] askama::Error),
31
32 #[error("SMTP error: {0}")]
34 SmtpError(String),
35
36 #[error("AWS SES error: {0}")]
38 AwsSesError(String),
39
40 #[error("email configuration error: {0}")]
42 ConfigError(String),
43
44 #[error("I/O error: {0}")]
46 IoError(#[from] std::io::Error),
47
48 #[error("serialization error: {0}")]
50 SerializationError(#[from] serde_json::Error),
51}
52
53impl EmailError {
54 #[must_use]
56 pub fn smtp<T: Into<String>>(msg: T) -> Self {
57 Self::SmtpError(msg.into())
58 }
59
60 #[must_use]
62 pub fn aws_ses<T: Into<String>>(msg: T) -> Self {
63 Self::AwsSesError(msg.into())
64 }
65
66 #[must_use]
68 pub fn config<T: Into<String>>(msg: T) -> Self {
69 Self::ConfigError(msg.into())
70 }
71}