From 4d74e38a515bc14381e1342afdf5ee2ec345f589 Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Thu, 30 May 2024 13:03:15 +0100 Subject: chore: handle rate limited responses (#2057) For Atuin Cloud, we rate limit login attempts (and a few other endpoints). Ensure that the user gets a descriptive response For self hosted users, if you wish to rate limit, I'd suggest configuring this with your reverse proxy. --- crates/atuin-client/src/api_client.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/atuin-client/src/api_client.rs b/crates/atuin-client/src/api_client.rs index f31a796e..7481c39a 100644 --- a/crates/atuin-client/src/api_client.rs +++ b/crates/atuin-client/src/api_client.rs @@ -86,6 +86,10 @@ pub async fn login(address: &str, req: LoginRequest) -> Result { .send() .await?; + if resp.status() == StatusCode::TOO_MANY_REQUESTS { + bail!("Rate limited. Too many login attempts."); + } + if !ensure_version(&resp)? { bail!("could not login due to version mismatch"); } @@ -157,6 +161,10 @@ async fn handle_resp_error(resp: Response) -> Result { ); } + if status == StatusCode::TOO_MANY_REQUESTS { + bail!("Rate limited; please wait before doing that again"); + } + if !status.is_success() { if let Ok(error) = resp.json::().await { let reason = error.reason; -- cgit v1.3.1