1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use super::super::utils::http_get;
use crate::error::{Error, Result};
use serde_json::Value;
use std::collections::HashMap;
fn check_status_in_body(resp: String) -> Result<String> {
let obj = serde_json::from_str::<HashMap<String, Value>>(&resp);
if obj.is_err() {
return Ok(resp);
}
match obj.unwrap().get("status") {
Some(status) => {
if status.as_str().unwrap() != "ok" {
Err(Error(resp))
} else {
Ok(resp)
}
}
None => Ok(resp),
}
}
pub(super) fn huobi_http_get(url: &str) -> Result<String> {
let ret = http_get(url, None);
match ret {
Ok(resp) => check_status_in_body(resp),
Err(_) => ret,
}
}