trade: if confirmation failure response contains a message, keep it so the user can see it (#329)

This commit is contained in:
Carson McManus 2023-10-08 11:12:34 -04:00 committed by GitHub
parent 94a3210f09
commit 7eb62cfa7b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -109,8 +109,12 @@ where
return Err(ConfirmerError::InvalidTokens);
}
if !body.success {
if let Some(msg) = body.message {
return Err(ConfirmerError::RemoteFailureWithMessage(msg));
} else {
return Err(ConfirmerError::RemoteFailure);
}
}
Ok(body.conf)
}
@ -162,8 +166,12 @@ where
return Err(ConfirmerError::InvalidTokens);
}
if !body.success {
if let Some(msg) = body.message {
return Err(ConfirmerError::RemoteFailureWithMessage(msg));
} else {
return Err(ConfirmerError::RemoteFailure);
}
}
Ok(())
}
@ -237,8 +245,12 @@ where
return Err(ConfirmerError::InvalidTokens);
}
if !body.success {
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<serde_json::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<bool>,
#[serde(default)]
pub conf: Vec<Confirmation>,
#[serde(default)]
pub message: Option<String>,
}
#[derive(Debug, Clone, Copy, Deserialize)]
#[derive(Debug, Clone, Deserialize)]
pub struct SendConfirmationResponse {
pub success: bool,
#[serde(default)]
pub needsauth: Option<bool>,
#[serde(default)]
pub message: Option<String>,
}
fn build_time_bytes(time: u64) -> [u8; 8] {