1#[derive(Clone, Copy, Debug, PartialEq, Eq)]
3pub enum MailError {
4 Configuration,
6 Address,
8 Header,
10 Message,
12 Attachment,
14 Size,
16 Template,
18 Connection,
20 Authentication,
22 Tls,
24 Temporary,
26 Permanent,
28 Timeout,
30 CaptureFull,
32 Queue,
34}
35impl MailError {
36 pub fn category(self) -> &'static str {
38 match self {
39 Self::Configuration => "configuration",
40 Self::Address => "address",
41 Self::Header => "header",
42 Self::Message => "message",
43 Self::Attachment => "attachment",
44 Self::Size => "size",
45 Self::Template => "template",
46 Self::Connection => "connection",
47 Self::Authentication => "authentication",
48 Self::Tls => "tls",
49 Self::Temporary => "temporary",
50 Self::Permanent => "permanent",
51 Self::Timeout => "timeout",
52 Self::CaptureFull => "capture_full",
53 Self::Queue => "queue",
54 }
55 }
56 pub fn retryable(self) -> bool {
58 matches!(self, Self::Temporary | Self::Connection | Self::Timeout)
59 }
60}
61impl std::fmt::Display for MailError {
62 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
63 write!(f, "Mail operation failed ({})", self.category())
64 }
65}
66impl std::error::Error for MailError {}
67impl From<askama::Error> for MailError {
68 fn from(_: askama::Error) -> Self {
69 Self::Template
70 }
71}
72impl From<MailError> for capy_core::AppError {
73 fn from(error: MailError) -> Self {
74 Self::Internal(error.into())
75 }
76}