fix(push): push folder and return error when tcp fail

This commit is contained in:
grimhilt
2024-03-01 17:56:52 +01:00
parent d8b2116aeb
commit 06bb51476b
5 changed files with 36 additions and 23 deletions

View File

@@ -1,9 +1,10 @@
use std::error::Error;
use lazy_static::lazy_static;
use std::sync::Mutex;
use reqwest::Client;
use reqwest::RequestBuilder;
use reqwest::multipart::Form;
use reqwest::{Response, Error, Method};
use reqwest::{Response, Method};
use reqwest::header::{HeaderValue, CONTENT_TYPE, HeaderMap, IntoHeaderName};
use crate::utils::api::ApiProps;
use crate::commands::config;
@@ -184,7 +185,7 @@ impl ApiBuilder {
self.set_request_manager();
}
let res = tokio::runtime::Runtime::new().unwrap().block_on(async {
let res_req = tokio::runtime::Runtime::new().unwrap().block_on(async {
match self.request.take() {
None => {
eprintln!("fatal: incorrect request");
@@ -199,7 +200,16 @@ impl ApiBuilder {
}
},
}
}).map_err(ApiError::RequestError)?;
});
// handle request error
let res = match res_req {
Err(err) => {
eprintln!("fatal: {}", err.source().unwrap());
std::process::exit(1);
},
Ok(res) => res,
};
if res.status().is_success() {
if need_text {
@@ -215,7 +225,7 @@ impl ApiBuilder {
}
}
pub async fn old_send(&mut self) -> Result<Response, Error> {
pub async fn old_send(&mut self) -> Result<Response, reqwest::Error> {
let mut request_manager = get_request_manager().lock().unwrap();
let request_manager = request_manager.as_mut().unwrap();
if !self.host.is_none()
@@ -237,9 +247,9 @@ impl ApiBuilder {
Some(req) => {
if let Some(headers) = &self.headers {
req.headers(headers.clone())
.send().await.map_err(Error::from)
.send().await.map_err(reqwest::Error::from)
} else {
req.send().await.map_err(Error::from)
req.send().await.map_err(reqwest::Error::from)
}
},
}