From 81c9cd0d4ad44920e3785fcb4a499e4f559c77f2 Mon Sep 17 00:00:00 2001 From: konsti Date: Mon, 13 Nov 2023 12:41:20 +0100 Subject: [PATCH] Print url for bad json error (#409) Split out from #382 --- crates/puffin-client/src/client.rs | 2 +- crates/puffin-client/src/error.rs | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/crates/puffin-client/src/client.rs b/crates/puffin-client/src/client.rs index a239397e1..1d71174d7 100644 --- a/crates/puffin-client/src/client.rs +++ b/crates/puffin-client/src/client.rs @@ -171,7 +171,7 @@ impl RegistryClient { match self.simple_impl(&url).await { Ok(text) => { return serde_json::from_str(&text) - .map_err(move |e| Error::from_json_err(e, String::new())); + .map_err(move |e| Error::from_json_err(e, url)); } Err(err) => { if err.status() == Some(StatusCode::NOT_FOUND) { diff --git a/crates/puffin-client/src/error.rs b/crates/puffin-client/src/error.rs index 614a904ca..0c32f1a01 100644 --- a/crates/puffin-client/src/error.rs +++ b/crates/puffin-client/src/error.rs @@ -41,11 +41,8 @@ pub enum Error { #[error(transparent)] RequestMiddlewareError(#[from] reqwest_middleware::Error), - #[error("Received some unexpected JSON: {source}")] - BadJson { - source: serde_json::Error, - url: String, - }, + #[error("Received some unexpected JSON from {url}")] + BadJson { source: serde_json::Error, url: Url }, #[error(transparent)] AsyncHttpRangeReader(#[from] AsyncHttpRangeReaderError), @@ -71,7 +68,7 @@ pub enum Error { } impl Error { - pub fn from_json_err(err: serde_json::Error, url: String) -> Self { + pub fn from_json_err(err: serde_json::Error, url: Url) -> Self { Self::BadJson { source: err, url } } }