Skip to content

Commit

Permalink
Send error message when rate limit is reached
Browse files Browse the repository at this point in the history
  • Loading branch information
Nutomic committed Nov 2, 2022
1 parent cb55917 commit 8fb89a0
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions crates/utils/src/rate_limit/mod.rs
@@ -1,8 +1,5 @@
use crate::{settings::structs::RateLimitConfig, utils::get_ip, IpAddr};
use actix_web::{
dev::{Service, ServiceRequest, ServiceResponse, Transform},
HttpResponse,
};
use crate::{error::LemmyError, settings::structs::RateLimitConfig, utils::get_ip, IpAddr};
use actix_web::dev::{Service, ServiceRequest, ServiceResponse, Transform};
use futures::future::{ok, Ready};
use rate_limiter::{RateLimitType, RateLimiter};
use std::{
Expand Down Expand Up @@ -135,10 +132,9 @@ where
service.call(req).await
} else {
let (http_req, _) = req.into_parts();
// if rate limit was hit, respond with http 400
Ok(ServiceResponse::new(
Ok(ServiceResponse::from_err(
LemmyError::from_message("error_rate_limited"),
http_req,
HttpResponse::BadRequest().finish(),
))
}
})
Expand Down

0 comments on commit 8fb89a0

Please sign in to comment.