mirror of
				https://github.com/yuezk/GlobalProtect-openconnect.git
				synced 2025-05-20 07:26:58 -04:00 
			
		
		
		
	refactor: refine the logging
This commit is contained in:
		| @@ -2,7 +2,7 @@ use thiserror::Error; | |||||||
|  |  | ||||||
| #[derive(Error, Debug)] | #[derive(Error, Debug)] | ||||||
| pub enum PortalError { | pub enum PortalError { | ||||||
|   #[error("Portal prelogin error: {0}")] |   #[error("Prelogin error: {0}")] | ||||||
|   PreloginError(String), |   PreloginError(String), | ||||||
|   #[error("Portal config error: {0}")] |   #[error("Portal config error: {0}")] | ||||||
|   ConfigError(String), |   ConfigError(String), | ||||||
|   | |||||||
| @@ -139,20 +139,23 @@ pub async fn prelogin(portal: &str, gp_params: &GpParams) -> anyhow::Result<Prel | |||||||
|     Err(anyhow!(PortalError::PreloginError(err.reason))) |     Err(anyhow!(PortalError::PreloginError(err.reason))) | ||||||
|   })?; |   })?; | ||||||
|  |  | ||||||
|   let prelogin = parse_res_xml(res_xml, is_gateway).map_err(|e| PortalError::PreloginError(e.to_string()))?; |   let prelogin = parse_res_xml(&res_xml, is_gateway).map_err(|err| { | ||||||
|  |     warn!("Parse response error, response: {}", res_xml); | ||||||
|  |     PortalError::PreloginError(err.to_string()) | ||||||
|  |   })?; | ||||||
|  |  | ||||||
|   Ok(prelogin) |   Ok(prelogin) | ||||||
| } | } | ||||||
|  |  | ||||||
| fn parse_res_xml(res_xml: String, is_gateway: bool) -> anyhow::Result<Prelogin> { | fn parse_res_xml(res_xml: &str, is_gateway: bool) -> anyhow::Result<Prelogin> { | ||||||
|   let doc = Document::parse(&res_xml)?; |   let doc = Document::parse(res_xml)?; | ||||||
|  |  | ||||||
|   let status = xml::get_child_text(&doc, "status") |   let status = xml::get_child_text(&doc, "status") | ||||||
|     .ok_or_else(|| anyhow::anyhow!("Prelogin response does not contain status element"))?; |     .ok_or_else(|| anyhow::anyhow!("Prelogin response does not contain status element"))?; | ||||||
|   // Check the status of the prelogin response |   // Check the status of the prelogin response | ||||||
|   if status.to_uppercase() != "SUCCESS" { |   if status.to_uppercase() != "SUCCESS" { | ||||||
|     let msg = xml::get_child_text(&doc, "msg").unwrap_or(String::from("Unknown error")); |     let msg = xml::get_child_text(&doc, "msg").unwrap_or(String::from("Unknown error")); | ||||||
|     bail!("Prelogin failed: {}", msg) |     bail!("{}", msg) | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   let region = xml::get_child_text(&doc, "region").unwrap_or_else(|| { |   let region = xml::get_child_text(&doc, "region").unwrap_or_else(|| { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user