From 96e76d7f72dee9a482dbe19e049f147fb121fdf6 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Tue, 19 Nov 2024 13:38:13 +0100 Subject: [PATCH] client: use correct error for protocol errors The 'Anyhow' error is not useful and meant for throw-away errors which cannot be dealt with anyway, and we'd like to be able to tell apart network problems from actual HTTP responses, so that we can potentially try a different node in a cluster connection. Signed-off-by: Wolfgang Bumiller --- proxmox-client/src/client.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/proxmox-client/src/client.rs b/proxmox-client/src/client.rs index cf16247c..9b078a98 100644 --- a/proxmox-client/src/client.rs +++ b/proxmox-client/src/client.rs @@ -223,7 +223,10 @@ impl Client { } .map_err(|err| Error::internal("failed to build request", err))?; - let response = client.request(request).await.map_err(Error::Anyhow)?; + let response = client + .request(request) + .await + .map_err(|err| Error::Client(err.into()))?; if response.status() == StatusCode::UNAUTHORIZED { return Err(Error::Unauthorized); @@ -318,7 +321,11 @@ impl Client { .body(request.body.into()) .map_err(|err| Error::internal("error building login http request", err))?; - let api_response = self.client.request(request).await.map_err(Error::Anyhow)?; + let api_response = self + .client + .request(request) + .await + .map_err(|err| Error::Client(err.into()))?; if !api_response.status().is_success() { return Err(Error::api(api_response.status(), "authentication failed")); }