diff options
| author | Conrad Ludgate <conradludgate@gmail.com> | 2023-09-26 14:44:56 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-26 14:44:56 +0100 |
| commit | bdba88c11f21cef8185e6eebf34be2343d748799 (patch) | |
| tree | 88e898c35f0f24a9c65ad4bf36bd4dc4c786e6d5 /atuin-client/src | |
| parent | refactor: Duplications reduced in order to align implementations of reading h... (diff) | |
| download | atuin-bdba88c11f21cef8185e6eebf34be2343d748799.zip | |
better sync error messages (#1254)
Diffstat (limited to 'atuin-client/src')
| -rw-r--r-- | atuin-client/src/api_client.rs | 16 |
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<()> { |
