Skip to content

Commit

Permalink
Remove to_json and add to_string
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanUkhov committed Oct 3, 2024
1 parent 5a494f3 commit 8978b94
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions google-apis-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,11 @@ where
let (parts, body) = response.into_parts();
let success = parts.status.is_success();
let bytes = to_bytes(body).await.unwrap_or_default();
let error = if !success { to_json(&bytes) } else { None };
let error = if !success {
json::from_str(&to_string(&bytes)).ok()
} else {
None
};
let response = to_response(parts, bytes);

if !success {
Expand Down Expand Up @@ -776,8 +780,8 @@ where
}

#[doc(hidden)]
pub fn to_json(bytes: &hyper::body::Bytes) -> Option<json::Value> {
json::from_str(&String::from_utf8_lossy(&bytes)).ok()
pub fn to_string(bytes: &hyper::body::Bytes) -> std::borrow::Cow<'_, str> {
String::from_utf8_lossy(&bytes)
}

#[doc(hidden)]
Expand Down

0 comments on commit 8978b94

Please sign in to comment.