Skip to content
Clone
39d7e6b
39 lines 939 B Rust
use std::fmt;
use redis::RedisError;
#[derive(Debug)]
pub enum CacheError {
Serialization(String),
Backend(RedisError),
}
impl fmt::Display for CacheError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
CacheError::Serialization(msg) => write!(f, "cache serialization error: {msg}"),
CacheError::Backend(err) => write!(f, "cache backend error: {err}"),
}
}
}
impl std::error::Error for CacheError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
CacheError::Backend(err) => Some(err),
_ => None,
}
}
}
impl From<RedisError> for CacheError {
fn from(err: RedisError) -> Self {
CacheError::Backend(err)
}
}
impl From<serde_json::Error> for CacheError {
fn from(err: serde_json::Error) -> Self {
CacheError::Serialization(err.to_string())
}
}