diff --git a/libpaket/src/utils.rs b/libpaket/src/utils.rs index 1d22cb2..632a23b 100644 --- a/libpaket/src/utils.rs +++ b/libpaket/src/utils.rs @@ -179,15 +179,23 @@ macro_rules! request_json { macro_rules! parse_json_response { ($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("") { + 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 mut unused = std::collections::BTreeSet::new(); - println!("res({}): {}", stringify!($type), res); let res: Result<$type, _> = serde_ignored::deserialize(jd, |path| { unused.insert(path.to_string()); }); - println!("res({}): {:?}", stringify!($type), unused); let res: $type = match res { Ok(res) => res, @@ -200,15 +208,23 @@ macro_rules! parse_json_response { macro_rules! parse_json_response_from_apiresult { ($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("") { + 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 mut unused = std::collections::BTreeSet::new(); - println!("res({}): {}", stringify!($type), res); let res: Result, _> = serde_ignored::deserialize(jd, |path| { unused.insert(path.to_string()); }); - println!("res({}): {:?}", stringify!($type), unused); let res: LibraryResult<$type> = match res { Ok(res) => res.into(),