Skip to content

Commit

Permalink
Log type that has failed to deserialize itself from a request
Browse files Browse the repository at this point in the history
  • Loading branch information
Kobzol committed Dec 7, 2023
1 parent 5bf94e4 commit 85b7f83
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/github/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ impl GitHub {
let resp = self.req(method.clone(), url)?.send()?;
match resp.status() {
StatusCode::OK => Ok(Some(resp.json().with_context(|| {
format!("Failed to decode response body on {method} request to '{url}'")
format!("Failed to decode response body of type {} on {method} request to '{url}'", std::any::type_name::<T>())
})?)),
StatusCode::NOT_FOUND => Ok(None),
_ => Err(resp.custom_error_for_status().unwrap_err()),
Expand All @@ -786,7 +786,7 @@ impl GitHub {
.custom_error_for_status()?;

let res: GraphResult<R> = resp.json().with_context(|| {
format!("Failed to decode response body on graphql request with query '{query}'")
format!("Failed to decode response body of type {} on graphql request with query '{query}'", std::any::type_name::<R>())
})?;
if let Some(error) = res.errors.get(0) {
bail!("graphql error: {}", error.message);
Expand Down Expand Up @@ -825,7 +825,7 @@ impl GitHub {
}

f(resp.json().with_context(|| {
format!("Failed to deserialize response body for {method} request to '{next_url}'")
format!("Failed to deserialize response body of type {} for {method} request to '{next_url}'", std::any::type_name::<T>())
})?)?;
}
Ok(())
Expand Down
3 changes: 2 additions & 1 deletion src/team_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use log::{debug, info, trace};
use std::borrow::Cow;
use std::path::PathBuf;
use std::process::Command;
use anyhow::Context;

pub(crate) enum TeamApi {
Production,
Expand Down Expand Up @@ -47,7 +48,7 @@ impl TeamApi {
.unwrap_or_else(|_| Cow::Borrowed(rust_team_data::v1::BASE_URL));
let url = format!("{base}/{url}");
trace!("http request: GET {}", url);
Ok(reqwest::blocking::get(&url)?.error_for_status()?.json()?)
Ok(reqwest::blocking::get(&url)?.error_for_status()?.json().with_context(|| format!("Failed to deserialize response body of type {} for team API URL {url}", std::any::type_name::<T>()))?)
}
TeamApi::Local(ref path) => {
let dest = tempfile::tempdir()?;
Expand Down

0 comments on commit 85b7f83

Please sign in to comment.