rss2email_lib/email/
error.rs

1use std::fmt::Display;
2
3/// Represents all things that could go wrong
4/// while trying to send an email.
5#[derive(Debug)]
6#[allow(dead_code)]
7pub enum EmailError {
8  Config(String),
9  Request(Box<reqwest::Error>),
10  Io(String),
11  Other(String),
12}
13
14impl From<reqwest::Error> for EmailError {
15  fn from(e: reqwest::Error) -> Self {
16    Self::Request(Box::new(e))
17  }
18}
19
20impl From<resend_rs::error::Error> for EmailError {
21  fn from(value: resend_rs::error::Error) -> Self {
22    match value {
23      resend_rs::error::Error::ReqwestError(e) => Self::from(e),
24      resend_rs::error::Error::ResendError(e) => Self::Other(e),
25    }
26  }
27}
28
29impl Display for EmailError {
30  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31    match &self {
32      Self::Request(e) => write!(f, "{e}"),
33      Self::Config(e) | Self::Io(e) | Self::Other(e) => write!(f, "{e}"),
34    }
35  }
36}