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.
This commit is contained in:
Ellie Huxtable 2024-05-30 13:03:15 +01:00 committed by GitHub
parent 467f89c104
commit 4d74e38a51
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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;