From ecf6717195d077c6ce65b73c11f79c3151db0e7b Mon Sep 17 00:00:00 2001 From: robjtede Date: Sun, 28 Aug 2022 19:52:42 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20=20@=20a623c?= =?UTF-8?q?50e9c3d8ab25643ce2f660fe29a2ca5dc8c=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- settings.html | 4 +- src/actix_limitation/middleware.rs.html | 52 ++++++++++++++++++++++--- 2 files changed, 47 insertions(+), 9 deletions(-) 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)