From a304cddc5852d15d45bb41744f3021c38b39d36b Mon Sep 17 00:00:00 2001 From: Li Yazhou Date: Mon, 9 Oct 2023 18:09:47 +0800 Subject: [PATCH] tune the output --- core/src/client.rs | 4 ++++ core/src/error.rs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/core/src/client.rs b/core/src/client.rs index 84331992..405a7b0d 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) }