From 981b1169ee609c9d90940a5d6693d2927791868c Mon Sep 17 00:00:00 2001 From: DecDuck Date: Fri, 27 Dec 2024 12:15:12 +1100 Subject: [PATCH] fix(auth initiate): add better error message --- desktop/src-tauri/src/auth.rs | 17 ++++++++++------- desktop/src-tauri/src/remote.rs | 4 ++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/desktop/src-tauri/src/auth.rs b/desktop/src-tauri/src/auth.rs index c603a61d..9d6afb54 100644 --- a/desktop/src-tauri/src/auth.rs +++ b/desktop/src-tauri/src/auth.rs @@ -152,7 +152,7 @@ pub fn recieve_handshake(app: AppHandle, path: String) { app.emit("auth/finished", ()).unwrap(); } -async fn auth_initiate_wrapper() -> Result<(), RemoteAccessError> { +fn auth_initiate_wrapper() -> Result<(), RemoteAccessError> { let base_url = { let db_lock = DB.borrow_data().unwrap(); Url::parse(&db_lock.base_url.clone())? @@ -164,14 +164,17 @@ async fn auth_initiate_wrapper() -> Result<(), RemoteAccessError> { platform: env::consts::OS.to_string(), }; - let client = reqwest::Client::new(); - let response = client.post(endpoint.to_string()).json(&body).send().await?; + let client = reqwest::blocking::Client::new(); + let response = client.post(endpoint.to_string()).json(&body).send()?; if response.status() != 200 { - return Err(RemoteAccessError::InvalidRedirect); + let data = response.json::()?; + info!("Could not start handshake: {}", data.status_message); + + return Err(RemoteAccessError::HandshakeFailed(data.status_message)); } - let redir_url = response.text().await?; + let redir_url = response.text()?; let complete_redir_url = base_url.join(&redir_url)?; info!("opening web browser to continue authentication"); @@ -181,8 +184,8 @@ async fn auth_initiate_wrapper() -> Result<(), RemoteAccessError> { } #[tauri::command] -pub async fn auth_initiate<'a>() -> Result<(), String> { - let result = auth_initiate_wrapper().await; +pub fn auth_initiate<'a>() -> Result<(), String> { + let result = auth_initiate_wrapper(); if result.is_err() { return Err(result.err().unwrap().to_string()); } diff --git a/desktop/src-tauri/src/remote.rs b/desktop/src-tauri/src/remote.rs index 2d51443c..15591558 100644 --- a/desktop/src-tauri/src/remote.rs +++ b/desktop/src-tauri/src/remote.rs @@ -17,7 +17,7 @@ pub enum RemoteAccessError { ParsingError(ParseError), InvalidCodeError(u16), InvalidEndpoint, - HandshakeFailed, + HandshakeFailed(String), GameNotFound, InvalidResponse, InvalidRedirect, @@ -43,7 +43,7 @@ impl Display for RemoteAccessError { } RemoteAccessError::InvalidCodeError(error) => write!(f, "Invalid HTTP code {}", error), RemoteAccessError::InvalidEndpoint => write!(f, "Invalid drop endpoint"), - RemoteAccessError::HandshakeFailed => write!(f, "Failed to complete handshake"), + RemoteAccessError::HandshakeFailed(message) => write!(f, "Failed to complete handshake: {}", message), RemoteAccessError::GameNotFound => write!(f, "Could not find game on server"), RemoteAccessError::InvalidResponse => write!(f, "Server returned an invalid response"), RemoteAccessError::InvalidRedirect => write!(f, "Server redirect was invalid"),