Skip to content

Commit

Permalink
feat: add a SessionTimeout error (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
flaneur2020 authored Oct 9, 2023
1 parent 0d68afd commit 88da440
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ impl APIClient {
};
let resp = Retry::spawn(retry_strategy, req).await?;
if resp.status() != StatusCode::OK {
// TODO(liyz): currently it's not possible to distinguish between session timeout and server crashed
if resp.status() == StatusCode::NOT_FOUND {
return Err(Error::SessionTimeout(resp.text().await?));
}
let resp_err = QueryError {
code: resp.status().as_u16(),
message: resp.text().await?,
Expand Down
4 changes: 4 additions & 0 deletions core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ pub enum Error {
BadArgument(String),
Request(String),
IO(String),
// if you have not polled the next_page_uri for too long, the session will be expired, you'll get a 404
// on accessing this next page uri.
SessionTimeout(String),
InvalidResponse(response::QueryError),
InvalidPage(response::QueryError),
}
Expand All @@ -31,6 +34,7 @@ impl std::fmt::Display for Error {
Error::BadArgument(msg) => write!(f, "BadArgument: {msg}"),
Error::Request(msg) => write!(f, "RequestError: {msg}"),
Error::IO(msg) => write!(f, "IOError: {msg}"),
Error::SessionTimeout(msg) => write!(f, "SessionExpired: {msg}"),
Error::InvalidResponse(e) => {
write!(f, "ResponseError with {}: {}", e.code, e.message)
}
Expand Down

0 comments on commit 88da440

Please sign in to comment.