diff --git a/core/src/client.rs b/core/src/client.rs index 8ab07b3e..20a78e93 100644 --- a/core/src/client.rs +++ b/core/src/client.rs @@ -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?, diff --git a/core/src/error.rs b/core/src/error.rs index a5981571..6108fd22 100644 --- a/core/src/error.rs +++ b/core/src/error.rs @@ -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), } @@ -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) }