mirror of
https://github.com/OMGeeky/google-apis-rs.git
synced 2026-02-23 15:49:49 +01:00
Bug fix: It was not possible to use FileGetCall to download binary files
This commit is contained in:
committed by
Dennis Vestergaard Værum
parent
d71efba45b
commit
1f776ddc54
@@ -811,25 +811,15 @@ else {
|
||||
return Err(client::Error::HttpError(err))
|
||||
}
|
||||
Ok(mut res) => {
|
||||
let (res_parts, res_body) = res.into_parts();
|
||||
let res_body_string: String = String::from_utf8(
|
||||
hyper::body::to_bytes(res_body)
|
||||
.await
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.collect(),
|
||||
)
|
||||
.unwrap();
|
||||
let reconstructed_result =
|
||||
hyper::Response::from_parts(res_parts, res_body_string.clone().into());
|
||||
if !res.status().is_success() {
|
||||
let res_body_string = client::get_body_as_string(res.body_mut()).await;
|
||||
|
||||
if !reconstructed_result.status().is_success() {
|
||||
let json_server_error = json::from_str::<client::JsonServerError>(&res_body_string).ok();
|
||||
let server_error = json::from_str::<client::ServerError>(&res_body_string)
|
||||
.or_else(|_| json::from_str::<client::ErrorResponse>(&res_body_string).map(|r| r.error))
|
||||
.ok();
|
||||
|
||||
if let client::Retry::After(d) = dlg.http_failure(&reconstructed_result,
|
||||
if let client::Retry::After(d) = dlg.http_failure(&res,
|
||||
json_server_error,
|
||||
server_error) {
|
||||
sleep(d);
|
||||
@@ -837,7 +827,7 @@ else {
|
||||
}
|
||||
${delegate_finish}(false);
|
||||
return match json::from_str::<client::ErrorResponse>(&res_body_string){
|
||||
Err(_) => Err(client::Error::Failure(reconstructed_result)),
|
||||
Err(_) => Err(client::Error::Failure(res)),
|
||||
Ok(serr) => Err(client::Error::BadRequest(serr))
|
||||
}
|
||||
}
|
||||
@@ -846,7 +836,7 @@ else {
|
||||
${READER_SEEK | indent_all_but_first_by(6)}
|
||||
let mut client = &mut *self.hub.client.borrow_mut();
|
||||
let upload_result = {
|
||||
let url_str = &reconstructed_result.headers().get("Location").expect("LOCATION header is part of protocol").to_str().unwrap();
|
||||
let url_str = &res.headers().get("Location").expect("LOCATION header is part of protocol").to_str().unwrap();
|
||||
if upload_url_from_server {
|
||||
dlg.store_upload_url(Some(url_str));
|
||||
}
|
||||
@@ -895,8 +885,10 @@ else {
|
||||
if enable_resource_parsing \
|
||||
% endif
|
||||
{
|
||||
let res_body_string = client::get_body_as_string(res.body_mut()).await;
|
||||
|
||||
match json::from_str(&res_body_string) {
|
||||
Ok(decoded) => (reconstructed_result, decoded),
|
||||
Ok(decoded) => (res, decoded),
|
||||
Err(err) => {
|
||||
dlg.response_json_decode_error(&res_body_string, &err);
|
||||
return Err(client::Error::JsonDecodeError(res_body_string, err));
|
||||
@@ -904,11 +896,11 @@ if enable_resource_parsing \
|
||||
}
|
||||
}\
|
||||
% if supports_download:
|
||||
else { (reconstructed_result, Default::default()) }\
|
||||
else { (res, Default::default()) }\
|
||||
% endif
|
||||
;
|
||||
% else:
|
||||
let result_value = reconstructed_result;
|
||||
let result_value = res;
|
||||
% endif
|
||||
|
||||
${delegate_finish}(true);
|
||||
|
||||
Reference in New Issue
Block a user