Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Improve download_zip_file error handling and logging #868

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions shinkai-bin/shinkai-node/src/network/node_shareable_logic.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use shinkai_http_api::node_api_router::APIError;
use shinkai_message_primitives::schemas::identity::{Identity, StandardIdentityType};
use std::sync::Arc;
use std::io::Read;
use std::sync::Arc;
use tokio::sync::Mutex;
use tokio_util::bytes::Bytes;

use crate::managers::identity_manager::IdentityManager;
use crate::managers::identity_manager::IdentityManagerTrait;
use ed25519_dalek::{ed25519::signature::SignerMut, SigningKey};
use hex;
use log::error;
use reqwest::StatusCode;
use shinkai_message_primitives::{
Expand All @@ -15,8 +17,6 @@ use shinkai_message_primitives::{
shinkai_utils::encryption::string_to_encryption_public_key,
};
use x25519_dalek::StaticSecret as EncryptionStaticKey;
use ed25519_dalek::{ed25519::signature::SignerMut, SigningKey};
use hex;

pub async fn validate_message_main_logic(
encryption_secret_key: &EncryptionStaticKey,
Expand Down Expand Up @@ -207,17 +207,18 @@ pub async fn download_zip_file(
.clone()
.try_sign(url.as_bytes())
.map_err(|e| APIError {
code: StatusCode::INTERNAL_SERVER_ERROR.as_u16(),
code: StatusCode::INTERNAL_SERVER_ERROR.as_u16(),
error: "Internal Server Error".to_string(),
message: format!("Failed to sign tool: {}", e),
})?;
})?;

let signature_bytes = signature.to_bytes();
let signature_hex = hex::encode(signature_bytes);

// Create the request with headers
let client = reqwest::Client::new();
let request = client.get(&url)
let request = client
.get(&url)
.header("X-Shinkai-Version", env!("CARGO_PKG_VERSION"))
.header("X-Shinkai-Identity", node_name)
.header("X-Shinkai-Signature", signature_hex);
Expand All @@ -234,6 +235,18 @@ pub async fn download_zip_file(
}
};

if !response.status().is_success() {
let status = response.status();
let body = response.text().await.unwrap_or_default();
println!("Download failed with status: {}", status);
println!("Response body: {}", body);
return Err(APIError {
code: status.as_u16(),
error: "Download Failed".to_string(),
message: format!("Failed to download asset from URL: {}", status),
});
}

// Get the bytes from the response
let bytes = match response.bytes().await {
Ok(bytes) => bytes,
Expand Down