Add logging of errors to K2V client

This commit is contained in:
Alex 2022-05-20 13:37:12 +02:00
parent 382e74c798
commit f24ee00f3e
Signed by: lx
GPG key ID: 0E496D15096376BE
3 changed files with 20 additions and 1 deletions

1
Cargo.lock generated
View file

@ -1584,6 +1584,7 @@ dependencies = [
"clap 3.1.18", "clap 3.1.18",
"garage_util 0.7.0", "garage_util 0.7.0",
"http", "http",
"log",
"rusoto_core", "rusoto_core",
"rusoto_credential", "rusoto_credential",
"rusoto_signature", "rusoto_signature",

View file

@ -6,6 +6,7 @@ edition = "2018"
[dependencies] [dependencies]
base64 = "0.13.0" base64 = "0.13.0"
http = "0.2.6" http = "0.2.6"
log = "0.4"
rusoto_core = "0.48.0" rusoto_core = "0.48.0"
rusoto_credential = "0.48.0" rusoto_credential = "0.48.0"
rusoto_signature = "0.48.0" rusoto_signature = "0.48.0"

View file

@ -4,6 +4,7 @@ use std::time::Duration;
use http::header::{ACCEPT, CONTENT_LENGTH, CONTENT_TYPE}; use http::header::{ACCEPT, CONTENT_LENGTH, CONTENT_TYPE};
use http::status::StatusCode; use http::status::StatusCode;
use http::HeaderMap; use http::HeaderMap;
use log::{debug, error};
use rusoto_core::{ByteStream, DispatchSignedRequest, HttpClient}; use rusoto_core::{ByteStream, DispatchSignedRequest, HttpClient};
use rusoto_credential::AwsCredentials; use rusoto_credential::AwsCredentials;
@ -311,11 +312,27 @@ impl K2vClient {
StatusCode::NOT_FOUND => return Err(Error::NotFound), StatusCode::NOT_FOUND => return Err(Error::NotFound),
StatusCode::NOT_MODIFIED => Vec::new(), 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( return Err(Error::InvalidResponse(
format!("invalid error code: {}", res.status).into(), 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 { Ok(Response {
body, body,