Skip to content

Commit

Permalink
fix: compatible with old servers when login 404
Browse files Browse the repository at this point in the history
  • Loading branch information
youngsofun committed Dec 12, 2024
1 parent ba058d5 commit 7804f7e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 2 additions & 4 deletions core/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,9 +649,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) => {
// old server
return Ok(());
}
Expand Down Expand Up @@ -838,7 +836,7 @@ impl APIClient {
status,
msg: String::from_utf8_lossy(&body).to_string(),
},
true,
false,
),
}
}
Expand Down
10 changes: 10 additions & 0 deletions core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ 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> {
let status_code = match self {
Error::Logic(status, ..) => Some(*status),
Error::Response { status, .. } => Some(*status),
Error::WithContext(err, _) => err.status_code(),
_ => None,
};
status_code
}
}

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

0 comments on commit 7804f7e

Please sign in to comment.