From 01d8c7ae4ccec15441162c071683396dc83fe769 Mon Sep 17 00:00:00 2001 From: neon_arch Date: Sun, 27 Aug 2023 20:52:16 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9A=99=EF=B8=8F=20=20refactor:=20add=20new?= =?UTF-8?q?=20pooling=20error=20type=20for=20pooling=20code=20(#180)(#178)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cache/error.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/cache/error.rs diff --git a/src/cache/error.rs b/src/cache/error.rs new file mode 100644 index 0000000..efd87c9 --- /dev/null +++ b/src/cache/error.rs @@ -0,0 +1,40 @@ +//! 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. +/// +/// This enum provides variants three different categories of errors: +/// * `RedisError` - This variant handles all errors related to `RedisError`, +/// * `PoolExhaustionWithConnectionDropError` - This variant handles the error +/// which occurs when all the connections in the connection pool return a connection +/// dropped redis error. +#[derive(Debug)] +pub enum PoolError { + RedisError(RedisError), + 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 {}