Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
Fix the rate limiter code to enable build
Browse files Browse the repository at this point in the history
  • Loading branch information
MBarwicki committed Nov 2, 2023
1 parent 24b3c6d commit 974a9ad
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions api/src/rate_limiter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl<'r> FromRequest<'r> for RateLimited {
async fn from_request(request: &'r Request<'_>) -> Outcome<Self, Self::Error> {
let rate_limiter: &RateLimiter = match request.rocket().state() {
None => {
return Outcome::Failure((
return Outcome::Error((
Status::InternalServerError,
ApiError::RateLimiterNotInState,
))
Expand All @@ -124,13 +124,13 @@ impl<'r> FromRequest<'r> for RateLimited {
};

let client_ip = match request.client_ip() {
None => return Outcome::Failure((Status::BadRequest, ApiError::FailedToGetClientIp)),
None => return Outcome::Error((Status::BadRequest, ApiError::FailedToGetClientIp)),
Some(x) => x,
};

match rate_limiter.do_rate_limit(client_ip) {
Ok(_) => Outcome::Success(RateLimited),
Err(_) => Outcome::Failure((Status::TooManyRequests, ApiError::TooManyRequests)),
Err(_) => Outcome::Error((Status::TooManyRequests, ApiError::TooManyRequests)),
}
}
}

0 comments on commit 974a9ad

Please sign in to comment.