aboutsummaryrefslogtreecommitdiffstats
path: root/atuin-client/src
diff options
context:
space:
mode:
authorConrad Ludgate <conradludgate@gmail.com>2023-09-26 14:44:56 +0100
committerGitHub <noreply@github.com>2023-09-26 14:44:56 +0100
commitbdba88c11f21cef8185e6eebf34be2343d748799 (patch)
tree88e898c35f0f24a9c65ad4bf36bd4dc4c786e6d5 /atuin-client/src
parentrefactor: Duplications reduced in order to align implementations of reading h... (diff)
downloadatuin-bdba88c11f21cef8185e6eebf34be2343d748799.zip
better sync error messages (#1254)
Diffstat (limited to 'atuin-client/src')
-rw-r--r--atuin-client/src/api_client.rs16
1 files changed, 13 insertions, 3 deletions
diff --git a/atuin-client/src/api_client.rs b/atuin-client/src/api_client.rs
index b6625a34..fbeea9aa 100644
--- a/atuin-client/src/api_client.rs
+++ b/atuin-client/src/api_client.rs
@@ -181,9 +181,19 @@ impl<'a> Client<'a> {
let resp = self.client.get(url).send().await?;
- let history = resp.json::<SyncHistoryResponse>().await?;
-
- Ok(history)
+ let status = resp.status();
+ if status.is_success() {
+ let history = resp.json::<SyncHistoryResponse>().await?;
+ Ok(history)
+ } else if status.is_client_error() {
+ let error = resp.json::<ErrorResponse>().await?.reason;
+ bail!("Could not fetch history: {error}.")
+ } else if status.is_server_error() {
+ let error = resp.json::<ErrorResponse>().await?.reason;
+ bail!("There was an error with the atuin sync service: {error}.\nIf the problem persists, contact the host")
+ } else {
+ bail!("There was an error with the atuin sync service: Status {status:?}.\nIf the problem persists, contact the host")
+ }
}
pub async fn post_history(&self, history: &[AddHistoryRequest]) -> Result<()> {