From bdba88c11f21cef8185e6eebf34be2343d748799 Mon Sep 17 00:00:00 2001 From: Conrad Ludgate Date: Tue, 26 Sep 2023 14:44:56 +0100 Subject: better sync error messages (#1254) --- atuin-client/src/api_client.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'atuin-client/src/api_client.rs') 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::().await?; - - Ok(history) + let status = resp.status(); + if status.is_success() { + let history = resp.json::().await?; + Ok(history) + } else if status.is_client_error() { + let error = resp.json::().await?.reason; + bail!("Could not fetch history: {error}.") + } else if status.is_server_error() { + let error = resp.json::().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<()> { -- cgit v1.3.1