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

Show Cloud error if present, and add verbosity #1006

Merged
merged 1 commit into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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