Spaces:
Runtime error
Runtime error
neon_arch
commited on
Commit
•
01d8c7a
1
Parent(s):
db93c31
⚙️ refactor: add new pooling error type for pooling code (#180)(#178)
Browse files- src/cache/error.rs +40 -0
src/cache/error.rs
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
//! This module provides the error enum to handle different errors associated while requesting data from
|
2 |
+
//! the redis server using an async connection pool.
|
3 |
+
use std::fmt;
|
4 |
+
|
5 |
+
use redis::RedisError;
|
6 |
+
|
7 |
+
/// A custom error type used for handling redis async pool associated errors.
|
8 |
+
///
|
9 |
+
/// This enum provides variants three different categories of errors:
|
10 |
+
/// * `RedisError` - This variant handles all errors related to `RedisError`,
|
11 |
+
/// * `PoolExhaustionWithConnectionDropError` - This variant handles the error
|
12 |
+
/// which occurs when all the connections in the connection pool return a connection
|
13 |
+
/// dropped redis error.
|
14 |
+
#[derive(Debug)]
|
15 |
+
pub enum PoolError {
|
16 |
+
RedisError(RedisError),
|
17 |
+
PoolExhaustionWithConnectionDropError,
|
18 |
+
}
|
19 |
+
|
20 |
+
impl fmt::Display for PoolError {
|
21 |
+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
22 |
+
match self {
|
23 |
+
PoolError::RedisError(redis_error) => {
|
24 |
+
if let Some(detail) = redis_error.detail() {
|
25 |
+
write!(f, "{}", detail)
|
26 |
+
} else {
|
27 |
+
write!(f, "")
|
28 |
+
}
|
29 |
+
}
|
30 |
+
PoolError::PoolExhaustionWithConnectionDropError => {
|
31 |
+
write!(
|
32 |
+
f,
|
33 |
+
"Error all connections from the pool dropped with connection error"
|
34 |
+
)
|
35 |
+
}
|
36 |
+
}
|
37 |
+
}
|
38 |
+
}
|
39 |
+
|
40 |
+
impl error_stack::Context for PoolError {}
|