Skip to content

Commit

Permalink
Properly handle file download (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
nkzou authored Mar 4, 2024
1 parent 29cb5a0 commit fcd99fa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
8 changes: 7 additions & 1 deletion .generator/src/generator/templates/api.j2
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,13 @@ impl {{ structName }} {
let local_content = local_resp.text().await?;

if !local_status.is_client_error() && !local_status.is_server_error() {
{%- if returnType %}
{%- if returnType == "Vec<u8>" %}
Ok(ResponseContent {
status: local_status,
content: local_content.clone(),
entity: Some(local_content.into_bytes()),
})
{%- elif returnType %}
match serde_json::from_str::<{{ returnType }}>(&local_content) {
Ok(e) => return Ok(ResponseContent {
status: local_status,
Expand Down
15 changes: 5 additions & 10 deletions src/datadogV2/api/api_cloud_workload_security.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,16 +317,11 @@ impl CloudWorkloadSecurityAPI {
let local_content = local_resp.text().await?;

if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<Vec<u8>>(&local_content) {
Ok(e) => {
return Ok(ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(crate::datadog::Error::Serde(e)),
};
Ok(ResponseContent {
status: local_status,
content: local_content.clone(),
entity: Some(local_content.into_bytes()),
})
} else {
let local_entity: Option<DownloadCloudWorkloadPolicyFileError> =
serde_json::from_str(&local_content).ok();
Expand Down

0 comments on commit fcd99fa

Please sign in to comment.