Serde errors

This commit is contained in:
Igor Katson 2022-12-08 20:43:02 +00:00
parent 6968a4e449
commit aacb8caaa3
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
5 changed files with 47 additions and 27 deletions

View file

@ -19,7 +19,18 @@ async fn check_response(r: reqwest::Response) -> anyhow::Result<reqwest::Respons
.text()
.await
.with_context(|| format!("cannot read response body for request to {url} ({status})"))?;
anyhow::bail!("{} -> {}: {}", url, status, body)
#[derive(Deserialize)]
struct HumanReadableError<'a> {
human_readable: Option<&'a str>,
}
let human_readable_internal_error = serde_json::from_str::<HumanReadableError<'_>>(&body)
.ok()
.and_then(|e| e.human_readable);
let body_display = human_readable_internal_error.unwrap_or(&body);
anyhow::bail!("{} -> {}: {}", url, status, body_display)
}
#[derive(Deserialize)]