You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by xu...@apache.org on 2024/12/13 10:43:48 UTC
(iceberg-rust) branch improve-rest-catalog created (now 3c2056ae)
This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a change to branch improve-rest-catalog
in repository https://gitbox.apache.org/repos/asf/iceberg-rust.git
at 3c2056ae chore: Add more debug message inside error
This branch includes the following new commits:
new 3c2056ae chore: Add more debug message inside error
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(iceberg-rust) 01/01: chore: Add more debug message inside error
Posted by xu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a commit to branch improve-rest-catalog
in repository https://gitbox.apache.org/repos/asf/iceberg-rust.git
commit 3c2056ae802bfaa104f45c9fd7eb3e2eea9cd756
Author: Xuanwo <gi...@xuanwo.io>
AuthorDate: Fri Dec 13 18:43:21 2024 +0800
chore: Add more debug message inside error
Signed-off-by: Xuanwo <gi...@xuanwo.io>
---
crates/catalog/rest/src/client.rs | 58 +++++++++++++++++++++++++++++++++------
1 file changed, 49 insertions(+), 9 deletions(-)
diff --git a/crates/catalog/rest/src/client.rs b/crates/catalog/rest/src/client.rs
index 53dcd4ce..7027edef 100644
--- a/crates/catalog/rest/src/client.rs
+++ b/crates/catalog/rest/src/client.rs
@@ -134,28 +134,39 @@ impl HttpClient {
.request(Method::POST, &self.token_endpoint)
.form(¶ms)
.build()?;
+ let auth_url = auth_req.url().clone();
let auth_resp = self.client.execute(auth_req).await?;
let auth_res: TokenResponse = if auth_resp.status().as_u16() == OK {
- let text = auth_resp.bytes().await?;
+ let text = auth_resp
+ .bytes()
+ .await
+ .map_err(|err| err.with_url(auth_url.clone()))?;
Ok(serde_json::from_slice(&text).map_err(|e| {
Error::new(
ErrorKind::Unexpected,
"Failed to parse response from rest catalog server!",
)
+ .with_context("operation", "auth")
+ .with_context("url", auth_url.to_string())
.with_context("json", String::from_utf8_lossy(&text))
.with_source(e)
})?)
} else {
let code = auth_resp.status();
- let text = auth_resp.bytes().await?;
+ let text = auth_resp
+ .bytes()
+ .await
+ .map_err(|err| err.with_url(auth_url.clone()))?;
let e: ErrorResponse = serde_json::from_slice(&text).map_err(|e| {
Error::new(
ErrorKind::Unexpected,
"Failed to parse response from rest catalog server!",
)
- .with_context("json", String::from_utf8_lossy(&text))
.with_context("code", code.to_string())
+ .with_context("operation", "auth")
+ .with_context("url", auth_url.to_string())
+ .with_context("json", String::from_utf8_lossy(&text))
.with_source(e)
})?;
Err(Error::from(e))
@@ -193,28 +204,41 @@ impl HttpClient {
) -> Result<R> {
self.authenticate(&mut request).await?;
+ let method = request.method().clone();
+ let url = request.url().clone();
+
let resp = self.client.execute(request).await?;
if resp.status().as_u16() == SUCCESS_CODE {
- let text = resp.bytes().await?;
+ let text = resp
+ .bytes()
+ .await
+ .map_err(|err| err.with_url(url.clone()))?;
Ok(serde_json::from_slice::<R>(&text).map_err(|e| {
Error::new(
ErrorKind::Unexpected,
"Failed to parse response from rest catalog server!",
)
+ .with_context("method", method.to_string())
+ .with_context("url", url.to_string())
.with_context("json", String::from_utf8_lossy(&text))
.with_source(e)
})?)
} else {
let code = resp.status();
- let text = resp.bytes().await?;
+ let text = resp
+ .bytes()
+ .await
+ .map_err(|err| err.with_url(url.clone()))?;
let e = serde_json::from_slice::<E>(&text).map_err(|e| {
Error::new(
ErrorKind::Unexpected,
"Failed to parse response from rest catalog server!",
)
- .with_context("json", String::from_utf8_lossy(&text))
.with_context("code", code.to_string())
+ .with_context("method", method.to_string())
+ .with_context("url", url.to_string())
+ .with_context("json", String::from_utf8_lossy(&text))
.with_source(e)
})?;
Err(e.into())
@@ -227,20 +251,28 @@ impl HttpClient {
) -> Result<()> {
self.authenticate(&mut request).await?;
+ let method = request.method().clone();
+ let url = request.url().clone();
+
let resp = self.client.execute(request).await?;
if resp.status().as_u16() == SUCCESS_CODE {
Ok(())
} else {
let code = resp.status();
- let text = resp.bytes().await?;
+ let text = resp
+ .bytes()
+ .await
+ .map_err(|err| err.with_url(url.clone()))?;
let e = serde_json::from_slice::<E>(&text).map_err(|e| {
Error::new(
ErrorKind::Unexpected,
"Failed to parse response from rest catalog server!",
)
- .with_context("json", String::from_utf8_lossy(&text))
.with_context("code", code.to_string())
+ .with_context("method", method.to_string())
+ .with_context("url", url.to_string())
+ .with_context("json", String::from_utf8_lossy(&text))
.with_source(e)
})?;
Err(e.into())
@@ -255,19 +287,27 @@ impl HttpClient {
) -> Result<R> {
self.authenticate(&mut request).await?;
+ let method = request.method().clone();
+ let url = request.url().clone();
+
let resp = self.client.execute(request).await?;
if let Some(ret) = handler(&resp) {
Ok(ret)
} else {
let code = resp.status();
- let text = resp.bytes().await?;
+ let text = resp
+ .bytes()
+ .await
+ .map_err(|err| err.with_url(url.clone()))?;
let e = serde_json::from_slice::<E>(&text).map_err(|e| {
Error::new(
ErrorKind::Unexpected,
"Failed to parse response from rest catalog server!",
)
.with_context("code", code.to_string())
+ .with_context("method", method.to_string())
+ .with_context("url", url.to_string())
.with_context("json", String::from_utf8_lossy(&text))
.with_source(e)
})?;