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

feat: add a SessionTimeout error #251

Merged
merged 2 commits into from
Oct 9, 2023
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
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