This is an automated email from the ASF dual-hosted git repository.

liurenjie1024 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-rust.git


The following commit(s) were added to refs/heads/main by this push:
     new 947fbc15 fix(catalog/rest): Allow deserialize error with empty 
response (#1266)
947fbc15 is described below

commit 947fbc1529c14dbd584b64e995400fc0cf7e80f2
Author: Xuanwo <[email protected]>
AuthorDate: Sun Apr 27 17:34:15 2025 +0800

    fix(catalog/rest): Allow deserialize error with empty response (#1266)
    
    ## Which issue does this PR close?
    
    - Closes https://github.com/apache/iceberg-rust/issues/1234
    
    ## What changes are included in this PR?
    
    Allow deserialize error with empty response
    
    ## Are these changes tested?
    
    Unit tests.
    
    Signed-off-by: Xuanwo <[email protected]>
---
 crates/catalog/rest/src/client.rs | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/crates/catalog/rest/src/client.rs 
b/crates/catalog/rest/src/client.rs
index 36069c3e..778ec758 100644
--- a/crates/catalog/rest/src/client.rs
+++ b/crates/catalog/rest/src/client.rs
@@ -250,18 +250,21 @@ pub(crate) async fn deserialize_catalog_response<R: 
DeserializeOwned>(
 }
 
 /// Deserializes a unexpected catalog response into an error.
-///
-/// TODO: Eventually, this function should return an error response that is 
custom to the error
-/// codes that all endpoints share (400, 404, etc.).
 pub(crate) async fn deserialize_unexpected_catalog_error(response: Response) 
-> Error {
-    let (status, headers) = (response.status(), response.headers().clone());
+    let err = Error::new(
+        ErrorKind::Unexpected,
+        "Received response with unexpected status code",
+    )
+    .with_context("status", response.status().to_string())
+    .with_context("headers", format!("{:?}", response.headers()));
+
     let bytes = match response.bytes().await {
         Ok(bytes) => bytes,
         Err(err) => return err.into(),
     };
 
-    Error::new(ErrorKind::Unexpected, "Received unexpected response")
-        .with_context("status", status.to_string())
-        .with_context("headers", format!("{:?}", headers))
-        .with_context("json", String::from_utf8_lossy(&bytes))
+    if bytes.is_empty() {
+        return err;
+    }
+    err.with_context("json", String::from_utf8_lossy(&bytes))
 }

Reply via email to