Skip to content

Commit

Permalink
del reqwest::Error transform
Browse files Browse the repository at this point in the history
  • Loading branch information
ityuany committed Apr 17, 2024
1 parent b85f6f1 commit a05cbd0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
10 changes: 5 additions & 5 deletions crates/snm_core/src/model/snm_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ impl From<std::io::Error> for SnmError {
// }
// }

impl From<reqwest::Error> for SnmError {
fn from(_error: reqwest::Error) -> Self {
SnmError::UnknownError
}
}
// impl From<reqwest::Error> for SnmError {
// fn from(_error: reqwest::Error) -> Self {
// SnmError::UnknownError
// }
// }

// impl From<dialoguer::Error> for SnmError {
// fn from(_error: dialoguer::Error) -> Self {
Expand Down
8 changes: 6 additions & 2 deletions crates/snm_core/src/utils/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ impl DownloadBuilder {

let client = reqwest::Client::new();

let response = client.get(download_url).send().await?;
let response = client
.get(download_url)
.send()
.await
.expect(format!("download error {}", &download_url).as_str());

let response_status = response.status();

Expand Down Expand Up @@ -141,7 +145,7 @@ impl DownloadBuilder {
progress_bar.set_message(download_url.to_string());

while let Some(chunk) = stream.next().await {
let chunk = chunk?;
let chunk = chunk.expect("download stream chunk error");

file.write_all(&chunk).await?;

Expand Down
20 changes: 15 additions & 5 deletions crates/snm_node/src/snm_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::node_model::Lts;
use crate::node_model::NodeModel;
use crate::node_schedule::NodeSchedule;
use async_trait::async_trait;
use chrono::format;
use chrono::NaiveDate;
use chrono::Utc;
use colored::*;
Expand Down Expand Up @@ -43,9 +44,11 @@ impl SnmNode {
let host = self.snm_config.get_nodejs_host();
let node_list_url = format!("{}/dist/index.json", host);
let node_vec: Vec<NodeModel> = reqwest::get(&node_list_url)
.await?
.await
.expect(format!("get {} error", &node_list_url).as_str())
.json::<Vec<NodeModel>>()
.await?;
.await
.expect(format!("{} response transform to json failed", &node_list_url).as_str());
Ok(node_vec)
}

Expand All @@ -55,9 +58,11 @@ impl SnmNode {
let node_schedule_url = format!("{}/nodejs/Release/main/schedule.json", host);

let node_schedule_vec: Vec<NodeSchedule> = reqwest::get(&node_schedule_url)
.await?
.await
.expect(format!("get {} error", &node_schedule_url).as_str())
.json::<std::collections::HashMap<String, NodeSchedule>>()
.await?
.await
.expect(format!("{} response transform to json failed", &node_schedule_url).as_str())
.into_iter()
.map(|(v, mut schedule)| {
schedule.version = Some(v[1..].to_string());
Expand All @@ -75,7 +80,12 @@ impl SnmNode {
let host = self.snm_config.get_nodejs_host();
let url = format!("{}/dist/v{}/SHASUMS256.txt", host, node_version);

let sha256_str = reqwest::get(&url).await?.text().await?;
let sha256_str = reqwest::get(&url)
.await
.expect(format!("get {} error", &url).as_str())
.text()
.await
.expect("transform text error");

let sha256_map: std::collections::HashMap<String, String> = sha256_str
.lines()
Expand Down
7 changes: 6 additions & 1 deletion crates/snm_npm/src/snm_npm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,12 @@ impl ManageTrait for SnmNpm {
let npm_registry = self.snm_config.get_npm_registry_host();
let download_url = format!("{}/{}/{}", npm_registry, &self.prefix, &v);

let value: Value = reqwest::get(&download_url).await?.json().await?;
let value: Value = reqwest::get(&download_url)
.await
.expect(format!("download error {}", &download_url).as_str())
.json()
.await
.expect(format!("json error {}", &download_url).as_str());

let x = value
.get("dist")
Expand Down

0 comments on commit a05cbd0

Please sign in to comment.