Skip to content

Commit

Permalink
Handle the gateway endpoint error
Browse files Browse the repository at this point in the history
Related: #338
  • Loading branch information
yuezk committed Mar 25, 2024
1 parent 08bd4ef commit 2d1aa3b
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 16 deletions.
4 changes: 2 additions & 2 deletions apps/gpauth/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"all": true,
"request": true,
"scope": [
"http://**",
"https://**"
"http://*",
"https://*"
]
}
},
Expand Down
5 changes: 4 additions & 1 deletion apps/gpclient/src/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ use common::vpn_utils::find_csd_wrapper;
use gpapi::{
clap::args::Os,
credential::{Credential, PasswordCredential},
error::PortalError,
gateway::gateway_login,
gp_params::{ClientOs, GpParams},
portal::{prelogin, retrieve_config, PortalError, Prelogin},
portal::{prelogin, retrieve_config, Prelogin},
process::{
auth_launcher::SamlAuthLauncher,
users::{get_non_root_user, get_user_by_name},
Expand Down Expand Up @@ -152,6 +153,8 @@ impl<'a> ConnectHandler<'a> {
}

async fn connect_gateway_with_prelogin(&self, gateway: &str) -> anyhow::Result<()> {
info!("Treat the portal as the gateway, connecting...");

let mut gp_params = self.build_gp_params();
gp_params.set_is_gateway(true);

Expand Down
11 changes: 11 additions & 0 deletions crates/gpapi/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use thiserror::Error;

#[derive(Error, Debug)]
pub enum PortalError {
#[error("Portal prelogin error: {0}")]
PreloginError(String),
#[error("Portal config error: {0}")]
ConfigError(String),
#[error("Gateway error: {0}")]
GatewayError(String),
}
9 changes: 8 additions & 1 deletion crates/gpapi/src/gateway/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use urlencoding::encode;

use crate::{
credential::Credential,
error::PortalError,
gp_params::GpParams,
utils::{normalize_server, parse_gp_error, remove_url_scheme},
};
Expand All @@ -28,7 +29,13 @@ pub async fn gateway_login(gateway: &str, cred: &Credential, gp_params: &GpParam

info!("Gateway login, user_agent: {}", gp_params.user_agent());

let res = client.post(&login_url).form(&params).send().await?;
let res = client
.post(&login_url)
.form(&params)
.send()
.await
.map_err(|e| anyhow::anyhow!(PortalError::GatewayError(e.to_string())))?;

let status = res.status();

if status.is_client_error() || status.is_server_error() {
Expand Down
1 change: 1 addition & 0 deletions crates/gpapi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod auth;
pub mod credential;
pub mod error;
pub mod gateway;
pub mod gp_params;
pub mod portal;
Expand Down
2 changes: 1 addition & 1 deletion crates/gpapi/src/portal/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use specta::Type;

use crate::{
credential::{AuthCookieCredential, Credential},
error::PortalError,
gateway::{parse_gateways, Gateway},
gp_params::GpParams,
portal::PortalError,
utils::{normalize_server, parse_gp_error, remove_url_scheme, xml},
};

Expand Down
10 changes: 0 additions & 10 deletions crates/gpapi/src/portal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,3 @@ mod prelogin;

pub use config::*;
pub use prelogin::*;

use thiserror::Error;

#[derive(Error, Debug)]
pub enum PortalError {
#[error("Portal prelogin error: {0}")]
PreloginError(String),
#[error("Portal config error: {0}")]
ConfigError(String),
}
2 changes: 1 addition & 1 deletion crates/gpapi/src/portal/prelogin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use serde::Serialize;
use specta::Type;

use crate::{
error::PortalError,
gp_params::GpParams,
portal::PortalError,
utils::{base64, normalize_server, parse_gp_error, xml},
};

Expand Down

0 comments on commit 2d1aa3b

Please sign in to comment.