Skip to content

Commit

Permalink
fix: compatible with old servers when login 404 (#535)
Browse files Browse the repository at this point in the history
  • Loading branch information
youngsofun authored Dec 17, 2024
1 parent 2f7835b commit 1c3425c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
6 changes: 6 additions & 0 deletions cli/tests/00-base.result
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
1
1
b 2 false "{""k"":""v""}"
a 1 true [1,2]
100000
0 99999 99999 100000
1
2
Expand All @@ -11,12 +14,15 @@ with comment
"
a"
3
1
NULL
3.00 3.00 0.0000000170141183460469231731687303715884105727000 -0.0000000170141183460469231731687303715884105727000
Asia/Shanghai
3
0 0.00
1 1.00
2 2.00
2
[1,2,3] NULL (1,'ab')
NULL {'k1':'v1','k2':'v2'} (2,NULL)
1 NULL 1 ab
Expand Down
1 change: 1 addition & 0 deletions cli/tests/http/06-update.result
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
305104
610208
6 changes: 2 additions & 4 deletions core/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,9 +651,7 @@ impl APIClient {
let response = self.query_request_helper(request, true, false).await;
let response = match response {
Ok(r) => r,
Err(Error::Logic(status, ..)) | Err(Error::Response { status, .. })
if status == 404 =>
{
Err(e) if e.status_code() == Some(StatusCode::NOT_FOUND) => {
info!("login return 404, skip login on the old version server");
return Ok(());
}
Expand Down Expand Up @@ -846,7 +844,7 @@ impl APIClient {
status,
msg: String::from_utf8_lossy(&body).to_string(),
},
true,
false,
),
}
}
Expand Down
9 changes: 9 additions & 0 deletions core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ impl Error {
pub fn with_context(self, ctx: &str) -> Self {
Error::WithContext(Box::new(self), ctx.to_string())
}

pub fn status_code(&self) -> Option<StatusCode> {
match self {
Error::Logic(status, ..) => Some(*status),
Error::Response { status, .. } => Some(*status),
Error::WithContext(err, _) => err.status_code(),
_ => None,
}
}
}

impl std::fmt::Display for Error {
Expand Down

0 comments on commit 1c3425c

Please sign in to comment.