mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2025-04-02 18:31:50 -04:00
refactor: refine the logging
This commit is contained in:
parent
d94d730a44
commit
ae211a923a
@ -2,7 +2,7 @@ use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum PortalError {
|
||||
#[error("Portal prelogin error: {0}")]
|
||||
#[error("Prelogin error: {0}")]
|
||||
PreloginError(String),
|
||||
#[error("Portal config error: {0}")]
|
||||
ConfigError(String),
|
||||
|
@ -139,20 +139,23 @@ pub async fn prelogin(portal: &str, gp_params: &GpParams) -> anyhow::Result<Prel
|
||||
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)
|
||||
}
|
||||
|
||||
fn parse_res_xml(res_xml: String, is_gateway: bool) -> anyhow::Result<Prelogin> {
|
||||
let doc = Document::parse(&res_xml)?;
|
||||
fn parse_res_xml(res_xml: &str, is_gateway: bool) -> anyhow::Result<Prelogin> {
|
||||
let doc = Document::parse(res_xml)?;
|
||||
|
||||
let status = xml::get_child_text(&doc, "status")
|
||||
.ok_or_else(|| anyhow::anyhow!("Prelogin response does not contain status element"))?;
|
||||
// Check the status of the prelogin response
|
||||
if status.to_uppercase() != "SUCCESS" {
|
||||
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(|| {
|
||||
|
Loading…
Reference in New Issue
Block a user