diff --git a/web/src/lib.rs b/web/src/lib.rs index 5d49657..02cdab8 100644 --- a/web/src/lib.rs +++ b/web/src/lib.rs @@ -98,21 +98,21 @@ impl Http { req = req.json(data); } - req.send() - .await? - .error_for_status() + req.send().await } pub async fn fetch(url: &str, token: Auth) -> reqwest::Result { Self::request::<()>(reqwest::Method::GET, url, None, token) .await? + .error_for_status()? .json::() .await } pub async fn post(url: &str, data: &T, token: Auth) -> reqwest::Result<()> { Self::request(reqwest::Method::POST, url, Some(data), token) - .await?; + .await? + .error_for_status()?; Ok(()) } } diff --git a/web/src/page.rs b/web/src/page.rs index 42b924c..57b2fa8 100644 --- a/web/src/page.rs +++ b/web/src/page.rs @@ -299,12 +299,7 @@ pub fn DebugPage() -> impl IntoView { } } else { let url = format!("{URL_BASE}/dbg?id={fetch_url}"); - spawn_local(async move { - match Http::fetch::(&url, auth).await { - Ok(x) => set_object.set(Arc::new(x)), - Err(e) => set_object.set(Arc::new(serde_json::Value::String(e.to_string()))), - } - }); + spawn_local(async move { set_object.set(Arc::new(debug_fetch(&url, auth).await)) }); } } > @@ -385,3 +380,17 @@ pub fn SearchPage() -> impl IntoView { } } + +// this is a rather weird way to fetch but i want to see the bare error text if it fails! +async fn debug_fetch(url: &str, token: Auth) -> serde_json::Value { + match Http::request::<()>(reqwest::Method::GET, url, None, token).await { + Err(e) => serde_json::Value::String(format!("[!] failed sending request: {e}")), + Ok(res) => match res.text().await { + Err(e) => serde_json::Value::String(format!("[!] invalid response body: {e}")), + Ok(x) => match serde_json::from_str(&x) { + Err(_) => serde_json::Value::String(x), + Ok(v) => v, + }, + } + } +}