#[derive(Debug)]
pub enum Error {
ClientError(String),
DatabaseFieldError(String),
NotificationError(String),
}
impl Error {
pub fn from_client(msg: &str) -> Box<Self> {
Box::new(Error::ClientError(msg.to_string()))
}
pub fn from_notification(msg: &str) -> Box<Self> {
Box::new(Error::NotificationError(msg.to_string()))
}
pub fn from_database_field(msg: &str) -> Box<Self> {
Box::new(Error::DatabaseFieldError(msg.to_string()))
}
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::ClientError(msg) => write!(f, "Client error: {}", msg),
Error::DatabaseFieldError(msg) => write!(f, "Database error: {}", msg),
Error::NotificationError(msg) => write!(f, "Notification error: {}", msg),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::ClientError(_) => None,
Error::DatabaseFieldError(_) => None,
Error::NotificationError(_) => None,
}
}
}