File size: 1,263 Bytes
01d8c7a
 
 
 
 
 
 
 
 
1a22221
01d8c7a
1a22221
 
01d8c7a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
28
29
30
31
32
33
34
35
36
37
38
//! 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 {
    /// This variant handles all errors related to `RedisError`,
    RedisError(RedisError),
    /// This variant handles the errors which occurs when all the connections
    /// in the connection pool return a connection dropped redis error.
    PoolExhaustionWithConnectionDropError,
}

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"
                )
            }
        }
    }
}

impl error_stack::Context for PoolError {}