From 93931958277714fd738a8dd8ab965c39b5016f63 Mon Sep 17 00:00:00 2001 From: Nutomic Date: Thu, 3 Nov 2022 18:13:40 +0000 Subject: [PATCH] Send error message when rate limit is reached (#2527) * Send error message when rate limit is reached * l18n key --- crates/utils/src/rate_limit/mod.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/crates/utils/src/rate_limit/mod.rs b/crates/utils/src/rate_limit/mod.rs index 48911b5c..ed019255 100644 --- a/crates/utils/src/rate_limit/mod.rs +++ b/crates/utils/src/rate_limit/mod.rs @@ -1,8 +1,5 @@ -use crate::{utils::get_ip, IpAddr}; -use actix_web::{ - dev::{Service, ServiceRequest, ServiceResponse, Transform}, - HttpResponse, -}; +use crate::{error::LemmyError, utils::get_ip, IpAddr}; +use actix_web::dev::{Service, ServiceRequest, ServiceResponse, Transform}; use futures::future::{ok, Ready}; use rate_limiter::{RateLimitType, RateLimiter}; use serde::{Deserialize, Serialize}; @@ -177,10 +174,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("rate_limit_error"), http_req, - HttpResponse::BadRequest().finish(), )) } }) -- 2.44.1