|
@@ -10,7 +10,7 @@ use serde_json::Value;
|
|
|
use crate::http_tool::RestTool;
|
|
use crate::http_tool::RestTool;
|
|
|
use crate::response_base::ResponseData;
|
|
use crate::response_base::ResponseData;
|
|
|
use sha2::{Digest, Sha256};
|
|
use sha2::{Digest, Sha256};
|
|
|
-use tracing::error;
|
|
|
|
|
|
|
+use tracing::{error};
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
#[derive(Clone)]
|
|
|
pub struct CoinexSwapRest {
|
|
pub struct CoinexSwapRest {
|
|
@@ -628,29 +628,37 @@ impl CoinexSwapRest {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// 读取响应的内容
|
|
// 读取响应的内容
|
|
|
- let response = request_builder.send().await.unwrap();
|
|
|
|
|
- // 原始响应数据
|
|
|
|
|
- let res_json = format!("url: {}, response: {:?}", url, response);
|
|
|
|
|
- // info!("url: {}, http响应:response: {:?}", url, response);
|
|
|
|
|
- let is_success = response.status().is_success(); // 先检查状态码
|
|
|
|
|
-
|
|
|
|
|
- let text = response.text().await.unwrap();
|
|
|
|
|
-
|
|
|
|
|
- let data_json_str: Result<Value, serde_json::Error> = serde_json::from_str(text.as_str());
|
|
|
|
|
- match data_json_str {
|
|
|
|
|
- Ok(data_json) => {
|
|
|
|
|
- return if is_success && data_json["code"].to_string() == "0" {
|
|
|
|
|
- self.on_success_data(data_json["data"].clone())
|
|
|
|
|
- } else {
|
|
|
|
|
- // 3103 是订单不存在
|
|
|
|
|
- if data_json["code"].to_string() != "3103" {
|
|
|
|
|
- error!("请求成功,code码异常。原始http 响应数据:{}, text: {}", res_json, text);
|
|
|
|
|
|
|
+ let res = request_builder.send().await;
|
|
|
|
|
+ match res {
|
|
|
|
|
+ Ok(response) => {
|
|
|
|
|
+ let is_success = response.status().is_success(); // 先检查状态码
|
|
|
|
|
+ let text_result = response.text().await;
|
|
|
|
|
+ match text_result {
|
|
|
|
|
+ Ok(text) => {
|
|
|
|
|
+ let data_json_str: Result<Value, serde_json::Error> = serde_json::from_str(text.as_str());
|
|
|
|
|
+ match data_json_str {
|
|
|
|
|
+ Ok(data_json) => {
|
|
|
|
|
+ return if is_success && data_json["code"].to_string() == "0" {
|
|
|
|
|
+ self.on_success_data(data_json["data"].clone())
|
|
|
|
|
+ } else {
|
|
|
|
|
+ self.on_error_data(&text, &url, &body)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ Err(e) => {
|
|
|
|
|
+ error!("{} 请求完成,解析响应内容JSON失败 {} {}", url, text.as_str(), e);
|
|
|
|
|
+ self.on_error_data(&e.to_string(), &url, &body)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ Err(e) => {
|
|
|
|
|
+ error!("{} 请求完成,解析响应内容失败 {}", url, e);
|
|
|
|
|
+ self.on_error_data(&e.to_string(), &url, &body)
|
|
|
}
|
|
}
|
|
|
- self.on_error_data(&text, &url, &body)
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
Err(e) => {
|
|
Err(e) => {
|
|
|
- error!("请求成功,响应数据异常。原始http 响应数据:{}, text: {}", res_json, text);
|
|
|
|
|
|
|
+ // 异常情况
|
|
|
|
|
+ error!("{} 请求失败,网络错误 {}", url, e);
|
|
|
self.on_error_data(&e.to_string(), &url, &body)
|
|
self.on_error_data(&e.to_string(), &url, &body)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|