Skip to content

Commit

Permalink
Show Cloud error if present, and add verbosity
Browse files Browse the repository at this point in the history
  • Loading branch information
fantix committed May 1, 2023
1 parent 827e801 commit 76aa7ab
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
14 changes: 12 additions & 2 deletions src/cloud/client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::env;
use std::{env, fmt};
use std::fmt::Formatter;
use std::fs;
use std::io;
use std::path::PathBuf;
Expand All @@ -15,7 +16,6 @@ const EDGEDB_CLOUD_API_VERSION: &str = "v1/";
const EDGEDB_CLOUD_API_TIMEOUT: u64 = 10;

#[derive(Debug, serde::Deserialize, thiserror::Error)]
#[error("HTTP error: [{:?}] {}", code, status)]
pub struct ErrorResponse {
#[serde(skip, default)]
pub code: StatusCode,
Expand Down Expand Up @@ -345,6 +345,16 @@ y4u6fdOVhgIhAJ4pJLfdoWQsHPUOcnVG5fBgdSnoCJhGQyuGyp+NDu1q
}
}

impl fmt::Display for ErrorResponse {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
if let Some(error) = &self.error {
write!(f, "{}", error)
} else {
write!(f, "HTTP error: [{:?}] {}", self.code, self.status)
}
}
}

pub fn cloud_config_file(profile: &Option<String>) -> anyhow::Result<PathBuf> {
Ok(cloud_config_dir()?.join(format!("{}.json", profile.as_deref().unwrap_or("default"))))
}
Expand Down
6 changes: 3 additions & 3 deletions src/commands/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ pub fn show_ui(options: &Options, args: &UI) -> anyhow::Result<()> {
use_https = true;
}
Ok(status) => {
log::debug!(
"GET {} returned status code {}, retry HTTP.",
print::echo!(
"{} returned status code {}, retry HTTP.",
https_url,
status
);
}
Err(e) => {
log::debug!("GET {} failed: {:#}", https_url, e);
print::echo!("Failed to probe {}: {:#}, retry HTTP.", https_url, e);
}
}
}
Expand Down

0 comments on commit 76aa7ab

Please sign in to comment.