feat: libpaket utils APIChange detection
This commit is contained in:
parent
b7ca6d9b27
commit
ec5896df52
1 changed files with 22 additions and 6 deletions
|
@ -179,15 +179,23 @@ macro_rules! request_json {
|
||||||
|
|
||||||
macro_rules! parse_json_response {
|
macro_rules! parse_json_response {
|
||||||
($res: expr, $type: ty) => {{
|
($res: expr, $type: ty) => {{
|
||||||
let res = $res.text().await.unwrap();
|
let status = $res.status();
|
||||||
|
let res: String = $res.text().await.unwrap();
|
||||||
|
// Catch HTML Response early
|
||||||
|
if status == 200 {
|
||||||
|
let res = res.clone();
|
||||||
|
let res = res.trim();
|
||||||
|
if res.starts_with("<!DOCTYPE html>") {
|
||||||
|
println!("got html, exptected json with type {}", stringify!($type));
|
||||||
|
return Err(crate::LibraryError::APIChange);
|
||||||
|
}
|
||||||
|
}
|
||||||
let jd = &mut serde_json::Deserializer::from_str(res.as_str());
|
let jd = &mut serde_json::Deserializer::from_str(res.as_str());
|
||||||
let mut unused = std::collections::BTreeSet::new();
|
let mut unused = std::collections::BTreeSet::new();
|
||||||
|
|
||||||
println!("res({}): {}", stringify!($type), res);
|
|
||||||
let res: Result<$type, _> = serde_ignored::deserialize(jd, |path| {
|
let res: Result<$type, _> = serde_ignored::deserialize(jd, |path| {
|
||||||
unused.insert(path.to_string());
|
unused.insert(path.to_string());
|
||||||
});
|
});
|
||||||
println!("res({}): {:?}", stringify!($type), unused);
|
|
||||||
|
|
||||||
let res: $type = match res {
|
let res: $type = match res {
|
||||||
Ok(res) => res,
|
Ok(res) => res,
|
||||||
|
@ -200,15 +208,23 @@ macro_rules! parse_json_response {
|
||||||
|
|
||||||
macro_rules! parse_json_response_from_apiresult {
|
macro_rules! parse_json_response_from_apiresult {
|
||||||
($res: expr, $type: ty) => {{
|
($res: expr, $type: ty) => {{
|
||||||
let res = $res.text().await.unwrap();
|
let status = $res.status();
|
||||||
|
let res: String = $res.text().await.unwrap();
|
||||||
|
// Catch HTML Response early
|
||||||
|
if status == 200 {
|
||||||
|
let res = res.clone();
|
||||||
|
let res = res.trim();
|
||||||
|
if res.starts_with("<!DOCTYPE html>") {
|
||||||
|
println!("got html, exptected json with type {}", stringify!($type));
|
||||||
|
return Err(crate::LibraryError::APIChange);
|
||||||
|
}
|
||||||
|
}
|
||||||
let jd = &mut serde_json::Deserializer::from_str(res.as_str());
|
let jd = &mut serde_json::Deserializer::from_str(res.as_str());
|
||||||
let mut unused = std::collections::BTreeSet::new();
|
let mut unused = std::collections::BTreeSet::new();
|
||||||
|
|
||||||
println!("res({}): {}", stringify!($type), res);
|
|
||||||
let res: Result<APIResult<$type>, _> = serde_ignored::deserialize(jd, |path| {
|
let res: Result<APIResult<$type>, _> = serde_ignored::deserialize(jd, |path| {
|
||||||
unused.insert(path.to_string());
|
unused.insert(path.to_string());
|
||||||
});
|
});
|
||||||
println!("res({}): {:?}", stringify!($type), unused);
|
|
||||||
|
|
||||||
let res: LibraryResult<$type> = match res {
|
let res: LibraryResult<$type> = match res {
|
||||||
Ok(res) => res.into(),
|
Ok(res) => res.into(),
|
||||||
|
|
Loading…
Reference in a new issue