Skip to content

Commit 27e2a86

Browse files
committed
hotfix: Add error details so we can troubleshoot problem
Signed-off-by: Denys Fedoryshchenko <denys.f@collabora.com>
1 parent 93e6259 commit 27e2a86

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

src/azure.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,36 @@ async fn get_file_from_blob(filename: String) -> ReceivedFile {
440440
// is status anything else than 200?
441441
// TODO: Do we need to return headers as well or it is data leakage?
442442
if response.status() != 200 {
443-
eprintln!("Error getting blob: {:?}", response.status());
443+
let status = response.status();
444+
let headers = response.headers().clone();
445+
let ms_error_code = headers
446+
.get("x-ms-error-code")
447+
.and_then(|v| v.to_str().ok())
448+
.unwrap_or("<missing>");
449+
let ms_request_id = headers
450+
.get("x-ms-request-id")
451+
.and_then(|v| v.to_str().ok())
452+
.unwrap_or("<missing>");
453+
let content_type = headers
454+
.get("content-type")
455+
.and_then(|v| v.to_str().ok())
456+
.unwrap_or("<missing>");
457+
let body_preview = match response.bytes().await {
458+
Ok(bytes) => {
459+
let mut preview = String::from_utf8_lossy(&bytes).into_owned();
460+
const MAX_LEN: usize = 4096;
461+
if preview.len() > MAX_LEN {
462+
preview.truncate(MAX_LEN);
463+
preview.push_str("…<truncated>");
464+
}
465+
preview
466+
}
467+
Err(e) => format!("<failed to read body: {e}>"),
468+
};
469+
470+
eprintln!(
471+
"Error getting blob: {status} (x-ms-error-code={ms_error_code}, x-ms-request-id={ms_request_id}, content-type={content_type}) body={body_preview}"
472+
);
444473
return received_file;
445474
}
446475
received_file.headers = response.headers().clone();

0 commit comments

Comments
 (0)