summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEllie Huxtable <ellie@elliehuxtable.com>2024-04-02 16:52:45 +0100
committerGitHub <noreply@github.com>2024-04-02 16:52:45 +0100
commitbb0ea6c516db04f5e76a8bd667ecb3e724a708f4 (patch)
tree36b61629a2f89c2eb87d584470abd9190843c48d
parentf814f62267df068bd6f70f706876ac8acee5a79a (diff)
fix: report non-decodable errors correctly (#1915)
-rw-r--r--atuin-client/src/api_client.rs18
1 files changed, 11 insertions, 7 deletions
diff --git a/atuin-client/src/api_client.rs b/atuin-client/src/api_client.rs
index e5273c37..a19e5305 100644
--- a/atuin-client/src/api_client.rs
+++ b/atuin-client/src/api_client.rs
@@ -157,13 +157,17 @@ async fn handle_resp_error(resp: Response) -> Result<Response> {
);
}
- if status.is_client_error() {
- let error = resp.json::<ErrorResponse>().await?.reason;
- bail!("Could not fetch history, client error: {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 if !status.is_success() {
+ if !status.is_success() {
+ if let Ok(error) = resp.json::<ErrorResponse>().await {
+ let reason = error.reason;
+
+ if status.is_client_error() {
+ bail!("Could not fetch history, client error {status}: {reason}.")
+ }
+
+ bail!("There was an error with the atuin sync service, server error {status}: {reason}.\nIf the problem persists, contact the host")
+ }
+
bail!("There was an error with the atuin sync service: Status {status:?}.\nIf the problem persists, contact the host")
}