aboutsummaryrefslogtreecommitdiffstats
path: root/crates/atuin-client/src
diff options
context:
space:
mode:
authorEllie Huxtable <ellie@elliehuxtable.com>2024-05-30 13:03:15 +0100
committerGitHub <noreply@github.com>2024-05-30 13:03:15 +0100
commit4d74e38a515bc14381e1342afdf5ee2ec345f589 (patch)
tree211c78423d34135277296d054e91611f52788b0f /crates/atuin-client/src
parentfeat(ui): add login/register dialog (#2056) (diff)
downloadatuin-4d74e38a515bc14381e1342afdf5ee2ec345f589.zip
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.
Diffstat (limited to 'crates/atuin-client/src')
-rw-r--r--crates/atuin-client/src/api_client.rs8
1 files changed, 8 insertions, 0 deletions
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<LoginResponse> {
.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<Response> {
);
}
+ 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::<ErrorResponse>().await {
let reason = error.reason;