// use kxio::net::Response; use crate::{e, s}; pub struct APIResult { pub result: Result, } impl serde::Deserialize<'a>> APIResult { pub async fn new(response: kxio::net::Result) -> Self { match response { Ok(response) => { let text = response.text().await.unwrap_or_default(); let text = if text.is_empty() { s!("null") } else { text }; let result = serde_json::from_str::(&text) .map_err(|e| e.to_string()) .map_err(|e| { e!("{e}: {text}"); e }) .map_err(kxio::net::Error::from); Self { result } } Err(e) => Self { result: Err(e) }, } } }