1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use std::fmt::Display;

/// Represents all things that could go wrong
/// while trying to send an email.
#[derive(Debug)]
#[allow(dead_code)]
pub enum EmailError {
  Config(String),
  Request(Box<reqwest::Error>),
  Io(String),
  Other(String),
}

impl From<reqwest::Error> for EmailError {
  fn from(e: reqwest::Error) -> Self {
    Self::Request(Box::new(e))
  }
}

impl Display for EmailError {
  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
    match &self {
      Self::Request(e) => write!(f, "{e}"),
      Self::Config(e) | Self::Io(e) | Self::Other(e) => write!(f, "{e}"),
    }
  }
}