Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: compatible with old servers when login 404 #535

Merged
merged 3 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading