diff options
author | Alex Auvolat <alex@adnab.me> | 2022-05-20 13:37:12 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-05-20 13:37:20 +0200 |
commit | 413c64d7a93d21adbe75d4a13b08cf63e74a95c7 (patch) | |
tree | 454fc9e6572465afd306299c463fdf91fd7fac48 | |
parent | 64c193e3dbb536d5d3c2881bc9aebbb3e4e6272e (diff) | |
download | garage-413c64d7a93d21adbe75d4a13b08cf63e74a95c7.tar.gz garage-413c64d7a93d21adbe75d4a13b08cf63e74a95c7.zip |
Add logging of errors to K2V client
-rw-r--r-- | Cargo.lock | 1 | ||||
-rw-r--r-- | src/k2v-client/Cargo.toml | 1 | ||||
-rw-r--r-- | src/k2v-client/src/lib.rs | 19 |
3 files changed, 20 insertions, 1 deletions
@@ -1596,6 +1596,7 @@ dependencies = [ "clap 3.1.18", "garage_util 0.7.0", "http", + "log", "rusoto_core", "rusoto_credential", "rusoto_signature", diff --git a/src/k2v-client/Cargo.toml b/src/k2v-client/Cargo.toml index 84c6b8b2..6106f4db 100644 --- a/src/k2v-client/Cargo.toml +++ b/src/k2v-client/Cargo.toml @@ -6,6 +6,7 @@ edition = "2018" [dependencies] base64 = "0.13.0" http = "0.2.6" +log = "0.4" rusoto_core = "0.48.0" rusoto_credential = "0.48.0" rusoto_signature = "0.48.0" diff --git a/src/k2v-client/src/lib.rs b/src/k2v-client/src/lib.rs index ba1cd6ea..a5a7a0bb 100644 --- a/src/k2v-client/src/lib.rs +++ b/src/k2v-client/src/lib.rs @@ -4,6 +4,7 @@ use std::time::Duration; use http::header::{ACCEPT, CONTENT_LENGTH, CONTENT_TYPE}; use http::status::StatusCode; use http::HeaderMap; +use log::{debug, error}; use rusoto_core::{ByteStream, DispatchSignedRequest, HttpClient}; use rusoto_credential::AwsCredentials; @@ -311,11 +312,27 @@ impl K2vClient { StatusCode::NOT_FOUND => return Err(Error::NotFound), StatusCode::NOT_MODIFIED => Vec::new(), _ => { + let err_body = read_body(&mut res.headers, res.body) + .await + .unwrap_or_default(); + error!( + "Error response {}: {}", + res.status, + std::str::from_utf8(&err_body) + .map(String::from) + .unwrap_or_else(|_| base64::encode(&err_body)) + ); return Err(Error::InvalidResponse( format!("invalid error code: {}", res.status).into(), - )) + )); } }; + debug!( + "Response body: {}", + std::str::from_utf8(&body) + .map(String::from) + .unwrap_or_else(|_| base64::encode(&body)) + ); Ok(Response { body, |