mirror of
https://github.com/atuinsh/atuin.git
synced 2025-06-24 20:01:36 +02:00
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:
parent
467f89c104
commit
4d74e38a51
@ -86,6 +86,10 @@ pub async fn login(address: &str, req: LoginRequest) -> Result<LoginResponse> {
|
|||||||
.send()
|
.send()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
if resp.status() == StatusCode::TOO_MANY_REQUESTS {
|
||||||
|
bail!("Rate limited. Too many login attempts.");
|
||||||
|
}
|
||||||
|
|
||||||
if !ensure_version(&resp)? {
|
if !ensure_version(&resp)? {
|
||||||
bail!("could not login due to version mismatch");
|
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 !status.is_success() {
|
||||||
if let Ok(error) = resp.json::<ErrorResponse>().await {
|
if let Ok(error) = resp.json::<ErrorResponse>().await {
|
||||||
let reason = error.reason;
|
let reason = error.reason;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user