Handle the gateway endpoint error

Related: #338
This commit is contained in:
Kevin Yue
2024-03-25 20:35:01 +08:00
parent 08bd4efefa
commit 2d1aa3ba8c
8 changed files with 28 additions and 16 deletions

View File

@@ -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},
};
@@ -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() {