From 7eb62cfa7bed518806938277294099f1d2674997 Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Sun, 8 Oct 2023 11:12:34 -0400 Subject: [PATCH] trade: if confirmation failure response contains a message, keep it so the user can see it (#329) --- steamguard/src/confirmation.rs | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/steamguard/src/confirmation.rs b/steamguard/src/confirmation.rs index c30e38f..18ca6a9 100644 --- a/steamguard/src/confirmation.rs +++ b/steamguard/src/confirmation.rs @@ -109,7 +109,11 @@ where return Err(ConfirmerError::InvalidTokens); } if !body.success { - return Err(ConfirmerError::RemoteFailure); + if let Some(msg) = body.message { + return Err(ConfirmerError::RemoteFailureWithMessage(msg)); + } else { + return Err(ConfirmerError::RemoteFailure); + } } Ok(body.conf) } @@ -162,7 +166,11 @@ where return Err(ConfirmerError::InvalidTokens); } if !body.success { - return Err(ConfirmerError::RemoteFailure); + if let Some(msg) = body.message { + return Err(ConfirmerError::RemoteFailureWithMessage(msg)); + } else { + return Err(ConfirmerError::RemoteFailure); + } } Ok(()) @@ -237,7 +245,11 @@ where return Err(ConfirmerError::InvalidTokens); } if !body.success { - return Err(ConfirmerError::RemoteFailure); + if let Some(msg) = body.message { + return Err(ConfirmerError::RemoteFailureWithMessage(msg)); + } else { + return Err(ConfirmerError::RemoteFailure); + } } Ok(()) @@ -316,8 +328,10 @@ pub enum ConfirmerError { NetworkFailure(#[from] reqwest::Error), #[error("Failed to deserialize response: {0}")] DeserializeError(#[from] serde_path_to_error::Error), - #[error("Remote failure: Valve's server responded with a failure. This is likely not a steamguard-cli bug, Steam's confirmation API is just unreliable. Wait a bit and try again.")] + #[error("Remote failure: Valve's server responded with a failure and did not elaborate any further. This is likely not a steamguard-cli bug, Steam's confirmation API is just unreliable. Wait a bit and try again.")] RemoteFailure, + #[error("Remote failure: Valve's server responded with a failure and said: {0}")] + RemoteFailureWithMessage(String), #[error("Unknown error: {0}")] Unknown(#[from] anyhow::Error), } @@ -388,13 +402,17 @@ pub struct ConfirmationListResponse { pub needauth: Option, #[serde(default)] pub conf: Vec, + #[serde(default)] + pub message: Option, } -#[derive(Debug, Clone, Copy, Deserialize)] +#[derive(Debug, Clone, Deserialize)] pub struct SendConfirmationResponse { pub success: bool, #[serde(default)] pub needsauth: Option, + #[serde(default)] + pub message: Option, } fn build_time_bytes(time: u64) -> [u8; 8] {