diff --git a/apps/gpclient/src/connect.rs b/apps/gpclient/src/connect.rs index 0a0ed9a..36d9ccc 100644 --- a/apps/gpclient/src/connect.rs +++ b/apps/gpclient/src/connect.rs @@ -19,7 +19,7 @@ use gpapi::{ GP_USER_AGENT, }; use inquire::{Password, PasswordDisplayMode, Select, Text}; -use log::info; +use log::{info, warn}; use openconnect::Vpn; use crate::{cli::SharedArgs, GP_CLIENT_LOCK_FILE}; @@ -203,7 +203,7 @@ impl<'a> ConnectHandler<'a> { return Ok(()); }; - info!("Failed to connect portal with prelogin: {}", err); + warn!("Failed to connect portal with prelogin: {}", err); if err.root_cause().downcast_ref::().is_some() { info!("Trying the gateway authentication workflow..."); self.connect_gateway_with_prelogin(server).await?; diff --git a/changelog.md b/changelog.md index 297edfc..edc445a 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ # Changelog +## [Unreleased] + +- Log the detailed error message when network error occurs + ## 2.4.0 - 2024-12-26 - Upgrade to Tauri 2.0 diff --git a/crates/gpapi/src/error.rs b/crates/gpapi/src/error.rs index 6af7085..260b25e 100644 --- a/crates/gpapi/src/error.rs +++ b/crates/gpapi/src/error.rs @@ -4,10 +4,13 @@ use thiserror::Error; pub enum PortalError { #[error("Prelogin error: {0}")] PreloginError(String), + #[error("Portal config error: {0}")] ConfigError(String), - #[error("Network error: {0}")] + + #[error(transparent)] NetworkError(#[from] reqwest::Error), + #[error("TLS error")] TlsError, } diff --git a/crates/gpapi/src/gateway/login.rs b/crates/gpapi/src/gateway/login.rs index d99c0e9..a0f7854 100644 --- a/crates/gpapi/src/gateway/login.rs +++ b/crates/gpapi/src/gateway/login.rs @@ -31,12 +31,10 @@ pub async fn gateway_login(gateway: &str, cred: &Credential, gp_params: &GpParam info!("Perform gateway login, user_agent: {}", gp_params.user_agent()); - let res = client - .post(&login_url) - .form(¶ms) - .send() - .await - .map_err(|e| anyhow::anyhow!(PortalError::NetworkError(e)))?; + let res = client.post(&login_url).form(¶ms).send().await.map_err(|e| { + warn!("Network error: {:?}", e); + anyhow::anyhow!(PortalError::NetworkError(e)) + })?; let res = parse_gp_response(res).await.map_err(|err| { warn!("{err}"); diff --git a/crates/gpapi/src/portal/config.rs b/crates/gpapi/src/portal/config.rs index 9be4c76..37e18c3 100644 --- a/crates/gpapi/src/portal/config.rs +++ b/crates/gpapi/src/portal/config.rs @@ -111,12 +111,10 @@ pub async fn retrieve_config(portal: &str, cred: &Credential, gp_params: &GpPara info!("Retrieve the portal config, user_agent: {}", gp_params.user_agent()); - let res = client - .post(&url) - .form(¶ms) - .send() - .await - .map_err(|e| anyhow::anyhow!(PortalError::NetworkError(e)))?; + let res = client.post(&url).form(¶ms).send().await.map_err(|e| { + warn!("Network error: {:?}", e); + anyhow::anyhow!(PortalError::NetworkError(e)) + })?; let res_xml = parse_gp_response(res).await.or_else(|err| { if err.status == StatusCode::NOT_FOUND { diff --git a/crates/gpapi/src/portal/prelogin.rs b/crates/gpapi/src/portal/prelogin.rs index b4076d9..9d52189 100644 --- a/crates/gpapi/src/portal/prelogin.rs +++ b/crates/gpapi/src/portal/prelogin.rs @@ -116,12 +116,10 @@ pub async fn prelogin(portal: &str, gp_params: &GpParams) -> anyhow::Result