Skip to content

Commit

Permalink
fix: fix compatible with old servers when login 404 and other error h…
Browse files Browse the repository at this point in the history
…andlerings. (#524)

* fix compatible with old servers when login 404.

* fix retry on 503.

* fix error msg: dup "fail to".
  • Loading branch information
youngsofun authored Dec 5, 2024
1 parent a79a047 commit 8452064
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions core/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,9 @@ impl APIClient {
let response = self.query_request_helper(request, true, false).await;
let response = match response {
Ok(r) => r,
Err(Error::Logic(status, _ec)) if status == 404 => {
Err(Error::Logic(status, ..)) | Err(Error::Response { status, .. })
if status == 404 =>
{
// old server
return Ok(());
}
Expand Down Expand Up @@ -783,7 +785,7 @@ impl APIClient {
return Ok(response);
}
let body = response.bytes().await?;
if retry_if_503 || status == StatusCode::SERVICE_UNAVAILABLE {
if retry_if_503 && status == StatusCode::SERVICE_UNAVAILABLE {
// waiting for server to start
(Error::response_error(status, &body), true)
} else {
Expand Down Expand Up @@ -847,19 +849,15 @@ impl APIClient {
),
};
if !retry {
return Err(err.with_context(&format!(
"fail to {} {} after 3 reties",
request.method(),
request.url()
)));
return Err(err.with_context(&format!("{} {}", request.method(), request.url())));
}
match &err {
Error::AuthFailure(_) => {
if refreshed {
retries = 0;
} else if retries == 2 {
return Err(err.with_context(&format!(
"fail to {} {} after 3 reties",
"{} {} after 3 reties",
request.method(),
request.url()
)));
Expand All @@ -868,7 +866,7 @@ impl APIClient {
_ => {
if retries == 2 {
return Err(err.with_context(&format!(
"fail to {} {} after 3 reties",
"{} {} after 3 reties",
request.method(),
request.url()
)));
Expand Down

0 comments on commit 8452064

Please sign in to comment.