Skip to content

Commit 947fbc1

Browse files
authored
fix(catalog/rest): Allow deserialize error with empty response (#1266)
## Which issue does this PR close? - Closes #1234 ## What changes are included in this PR? Allow deserialize error with empty response ## Are these changes tested? Unit tests. Signed-off-by: Xuanwo <github@xuanwo.io>
1 parent 5677d44 commit 947fbc1

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

crates/catalog/rest/src/client.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -250,18 +250,21 @@ pub(crate) async fn deserialize_catalog_response<R: DeserializeOwned>(
250250
}
251251

252252
/// Deserializes a unexpected catalog response into an error.
253-
///
254-
/// TODO: Eventually, this function should return an error response that is custom to the error
255-
/// codes that all endpoints share (400, 404, etc.).
256253
pub(crate) async fn deserialize_unexpected_catalog_error(response: Response) -> Error {
257-
let (status, headers) = (response.status(), response.headers().clone());
254+
let err = Error::new(
255+
ErrorKind::Unexpected,
256+
"Received response with unexpected status code",
257+
)
258+
.with_context("status", response.status().to_string())
259+
.with_context("headers", format!("{:?}", response.headers()));
260+
258261
let bytes = match response.bytes().await {
259262
Ok(bytes) => bytes,
260263
Err(err) => return err.into(),
261264
};
262265

263-
Error::new(ErrorKind::Unexpected, "Received unexpected response")
264-
.with_context("status", status.to_string())
265-
.with_context("headers", format!("{:?}", headers))
266-
.with_context("json", String::from_utf8_lossy(&bytes))
266+
if bytes.is_empty() {
267+
return err;
268+
}
269+
err.with_context("json", String::from_utf8_lossy(&bytes))
267270
}

0 commit comments

Comments
 (0)