diff --git a/settings.html b/settings.html index f41e98d2f..ff977bab9 100644 --- a/settings.html +++ b/settings.html @@ -1,3 +1 @@ -Rustdoc settings

Rustdoc settings

Back
\ No newline at end of file +Rustdoc settings

Rustdoc settings

Back
\ No newline at end of file diff --git a/src/actix_limitation/middleware.rs.html b/src/actix_limitation/middleware.rs.html index a3cd6736c..b98482b78 100644 --- a/src/actix_limitation/middleware.rs.html +++ b/src/actix_limitation/middleware.rs.html @@ -103,6 +103,26 @@ 101 102 103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123
use std::{future::Future, pin::Pin, rc::Rc};
 
 use actix_session::SessionExt as _;
@@ -114,7 +134,7 @@
     web, Error, HttpResponse,
 };
 
-use crate::Limiter;
+use crate::{Error as LimitationError, Limiter};
 
 /// Rate limit middleware.
 #[derive(Debug, Default)]
@@ -191,12 +211,32 @@
         Box::pin(async move {
             let status = limiter.count(key.to_string()).await;
 
-            if status.is_err() {
-                log::warn!("Rate limit exceed error for {}", key);
+            if let Err(err) = status {
+                match err {
+                    LimitationError::LimitExceeded(_) => {
+                        log::warn!("Rate limit exceed error for {}", key);
 
-                Ok(req.into_response(
-                    HttpResponse::new(StatusCode::TOO_MANY_REQUESTS).map_into_right_body(),
-                ))
+                        Ok(req.into_response(
+                            HttpResponse::new(StatusCode::TOO_MANY_REQUESTS).map_into_right_body(),
+                        ))
+                    }
+                    LimitationError::Client(e) => {
+                        log::error!("Client request failed, redis error: {}", e);
+
+                        Ok(req.into_response(
+                            HttpResponse::new(StatusCode::INTERNAL_SERVER_ERROR)
+                                .map_into_right_body(),
+                        ))
+                    }
+                    _ => {
+                        log::error!("Count failed: {}", err);
+
+                        Ok(req.into_response(
+                            HttpResponse::new(StatusCode::INTERNAL_SERVER_ERROR)
+                                .map_into_right_body(),
+                        ))
+                    }
+                }
             } else {
                 service
                     .call(req)