2023-08-27 13:52:16 -04:00
|
|
|
//! This module provides the error enum to handle different errors associated while requesting data from
|
|
|
|
//! the redis server using an async connection pool.
|
|
|
|
use std::fmt;
|
|
|
|
|
|
|
|
use redis::RedisError;
|
|
|
|
|
|
|
|
/// A custom error type used for handling redis async pool associated errors.
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum PoolError {
|
2023-09-12 10:59:33 -04:00
|
|
|
/// This variant handles all errors related to `RedisError`,
|
2023-08-27 13:52:16 -04:00
|
|
|
RedisError(RedisError),
|
2023-09-12 10:59:33 -04:00
|
|
|
/// This variant handles the errors which occurs when all the connections
|
|
|
|
/// in the connection pool return a connection dropped redis error.
|
2023-08-27 13:52:16 -04:00
|
|
|
PoolExhaustionWithConnectionDropError,
|
2023-09-11 17:20:05 -04:00
|
|
|
SerializationError,
|
2023-09-09 12:17:29 -04:00
|
|
|
MissingValue,
|
2023-08-27 13:52:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for PoolError {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
match self {
|
|
|
|
PoolError::RedisError(redis_error) => {
|
|
|
|
if let Some(detail) = redis_error.detail() {
|
|
|
|
write!(f, "{}", detail)
|
|
|
|
} else {
|
|
|
|
write!(f, "")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PoolError::PoolExhaustionWithConnectionDropError => {
|
|
|
|
write!(
|
|
|
|
f,
|
|
|
|
"Error all connections from the pool dropped with connection error"
|
|
|
|
)
|
|
|
|
}
|
2023-09-09 12:17:29 -04:00
|
|
|
PoolError::MissingValue => {
|
|
|
|
write!(f, "The value is missing from the cache")
|
|
|
|
}
|
2023-09-11 17:20:05 -04:00
|
|
|
PoolError::SerializationError => {
|
|
|
|
write!(f, "Unable to serialize, deserialize from the cache")
|
|
|
|
}
|
2023-08-27 13:52:16 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl error_stack::Context for PoolError {}
|