Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"error decoding response body" is not enough #2373

Closed
Dushistov opened this issue Aug 5, 2024 · 3 comments
Closed

"error decoding response body" is not enough #2373

Dushistov opened this issue Aug 5, 2024 · 3 comments

Comments

@Dushistov
Copy link

I use reqwest (0.12.5) like this:

let resp = client.post(url).json(&data).send().await?;
resp.json().await?;

If error occured, I got reqwest::Error, but there is no URL in it,
so println!("{err}"); just gives:

error decoding response body

Because of I use 10 different url, it is not clear what exactly happens from error.

It would be nice, if error in case of json decode error contains URL.

@Tienisto
Copy link

Tienisto commented Aug 7, 2024

The debug string println!("{err:?}"); produces a more detailed information

@seanmonstar
Copy link
Owner

It also likely has the serde error as a cause, which isn't shown in the Display output on purpose. You're supposed to use some sort of error reporter if you want to crawl the error chain.

@seanmonstar seanmonstar closed this as not planned Won't fix, can't repro, duplicate, stale Aug 7, 2024
@Dushistov
Copy link
Author

@seanmonstar @Tienisto

May be it is not clear, but Response::json does not include URL,
and that is my problem here.

Obviosly Display doesn't help here at all.

Probable fix will be:

@@ -265,9 +265,10 @@ impl Response {
     #[cfg(feature = "json")]
     #[cfg_attr(docsrs, doc(cfg(feature = "json")))]
     pub async fn json<T: DeserializeOwned>(self) -> crate::Result<T> {
+        let url = *self.url.clone();
         let full = self.bytes().await?;
 
-        serde_json::from_slice(&full).map_err(crate::error::decode)
+        serde_json::from_slice(&full).map_err(|err| crate::error::decode(err).with_url(url))
     }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants