]> Untitled Git - lemmy.git/commitdiff
Adding IP to the rate limit request line. (#882)
authorDessalines <dessalines@users.noreply.github.com>
Wed, 1 Jul 2020 22:54:46 +0000 (18:54 -0400)
committerGitHub <noreply@github.com>
Wed, 1 Jul 2020 22:54:46 +0000 (18:54 -0400)
* Adding IP to the rate limit request line.

* Adding IP to the rate limit request line.

server/src/rate_limit/rate_limiter.rs

index 3e2ea787b5b3e84fce2f0aad56279cf1ef02bd42..20a617c2fe3097d4617750ed8cd0460df3c87f9c 100644 (file)
@@ -10,7 +10,7 @@ pub struct RateLimitBucket {
   allowance: f64,
 }
 
-#[derive(Eq, PartialEq, Hash, Debug, EnumIter, Copy, Clone)]
+#[derive(Eq, PartialEq, Hash, Debug, EnumIter, Copy, Clone, AsRefStr)]
 pub enum RateLimitType {
   Message,
   Register,
@@ -80,12 +80,21 @@ impl RateLimiter {
 
         if rate_limit.allowance < 1.0 {
           debug!(
-            "Rate limited IP: {}, time_passed: {}, allowance: {}",
-            ip, time_passed, rate_limit.allowance
+            "Rate limited type: {}, IP: {}, time_passed: {}, allowance: {}",
+            type_.as_ref(),
+            ip,
+            time_passed,
+            rate_limit.allowance
           );
           Err(
             APIError {
-              message: format!("Too many requests. {} per {} seconds", rate, per),
+              message: format!(
+                "Too many requests. type: {}, IP: {}, {} per {} seconds",
+                type_.as_ref(),
+                ip,
+                rate,
+                per
+              ),
             }
             .into(),
           )