improve client error message

This commit is contained in:
mbecker20
2024-05-25 13:40:05 -07:00
parent 99ccffbc38
commit 62e8943ebe
2 changed files with 8 additions and 2 deletions
+6 -1
View File
@@ -139,13 +139,18 @@ async fn handle_req<Res: DeserializeOwned>(
let status = res.status();
if status == StatusCode::OK {
if status.is_success() {
res.json().await.context("failed to parse response to json")
} else {
let text = res
.text()
.await
.context("failed to get response body as text")?;
if let Ok(json_error) =
serde_json::from_str::<serde_json::Value>(&text)
{
return Err(anyhow!("{status} | {json_error:?}"));
}
Err(anyhow!("{status} | {text}"))
}
}
@@ -150,8 +150,9 @@ pub enum HetznerVolumeFormat {
)]
#[allow(clippy::enum_variant_names)]
pub enum HetznerServerType {
#[default]
SharedIntel1Core2Ram20Disk,
// The lowest tier available at all locations
#[default]
SharedAmd2Core2Ram40Disk,
SharedArm2Core4Ram40Disk,
SharedIntel2Core4Ram40Disk,