From c970e808bccf8442ab8b5451111e401d92494800 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20H=C3=A4ggblad?= Date: Mon, 18 Nov 2024 16:04:10 +0100 Subject: [PATCH] Add code reference id --- .../src/commands/mod.rs | 7 +++++-- .../src/commands/register_device.rs | 4 +++- .../src/commands/update_account.rs | 1 + .../src/commands/update_device.rs | 3 ++- .../src/shared_state.rs | 18 +++++++++--------- .../crates/nym-vpn-lib/src/platform/error.rs | 17 +++++++++++++---- .../nym-vpn-lib/src/uniffi_custom_impls.rs | 1 + .../src/command_interface/protobuf/account.rs | 1 + .../src/command_interface/protobuf/error.rs | 3 +++ .../crates/nym-vpnd/src/service/error.rs | 15 ++++++++++++--- 10 files changed, 50 insertions(+), 20 deletions(-) diff --git a/nym-vpn-core/crates/nym-vpn-account-controller/src/commands/mod.rs b/nym-vpn-core/crates/nym-vpn-account-controller/src/commands/mod.rs index 715d3839ae..43b109171d 100644 --- a/nym-vpn-core/crates/nym-vpn-account-controller/src/commands/mod.rs +++ b/nym-vpn-core/crates/nym-vpn-account-controller/src/commands/mod.rs @@ -38,19 +38,22 @@ pub enum AccountCommandError { UpdateAccountEndpointFailure { message: String, message_id: Option, + code_reference_id: Option, base_url: Box, }, #[error("failed to update device state: {message}")] UpdateDeviceEndpointFailure { - message_id: Option, message: String, + message_id: Option, + code_reference_id: Option, }, #[error("failed to register device: {message}")] RegisterDeviceEndpointFailure { - message_id: Option, message: String, + message_id: Option, + code_reference_id: Option, }, #[error("no account stored")] diff --git a/nym-vpn-core/crates/nym-vpn-account-controller/src/commands/register_device.rs b/nym-vpn-core/crates/nym-vpn-account-controller/src/commands/register_device.rs index 1fee97579d..fd405f1191 100644 --- a/nym-vpn-core/crates/nym-vpn-account-controller/src/commands/register_device.rs +++ b/nym-vpn-core/crates/nym-vpn-account-controller/src/commands/register_device.rs @@ -98,13 +98,15 @@ pub(crate) async fn register_device( nym_vpn_api_client::response::extract_error_response(&err) .map(|e| { tracing::warn!( - "nym-vpn-api reports: message={}, message_id={:?}", + "nym-vpn-api reports: message={}, message_id={:?}, code_reference_id={:?}", e.message, e.message_id, + e.code_reference_id, ); AccountCommandError::RegisterDeviceEndpointFailure { message_id: e.message_id.clone(), message: e.message.clone(), + code_reference_id: e.code_reference_id.clone(), } }) .unwrap_or(AccountCommandError::General(err.to_string())) diff --git a/nym-vpn-core/crates/nym-vpn-account-controller/src/commands/update_account.rs b/nym-vpn-core/crates/nym-vpn-account-controller/src/commands/update_account.rs index 9a65d17d54..fe9aa8f0f3 100644 --- a/nym-vpn-core/crates/nym-vpn-account-controller/src/commands/update_account.rs +++ b/nym-vpn-core/crates/nym-vpn-account-controller/src/commands/update_account.rs @@ -109,6 +109,7 @@ pub(crate) async fn update_state( return Err(AccountCommandError::UpdateAccountEndpointFailure { message: e.message.clone(), message_id: e.message_id.clone(), + code_reference_id: e.code_reference_id.clone(), base_url: Box::new(vpn_api_client.current_url().clone()), }); } diff --git a/nym-vpn-core/crates/nym-vpn-account-controller/src/commands/update_device.rs b/nym-vpn-core/crates/nym-vpn-account-controller/src/commands/update_device.rs index b79b4c810b..5a9e18b5c4 100644 --- a/nym-vpn-core/crates/nym-vpn-account-controller/src/commands/update_device.rs +++ b/nym-vpn-core/crates/nym-vpn-account-controller/src/commands/update_device.rs @@ -108,8 +108,9 @@ pub(crate) async fn update_state( e.message_id ); AccountCommandError::UpdateDeviceEndpointFailure { - message_id: e.message_id.clone(), message: e.message.clone(), + message_id: e.message_id.clone(), + code_reference_id: e.code_reference_id.clone(), } }) .unwrap_or(AccountCommandError::General(err.to_string())) diff --git a/nym-vpn-core/crates/nym-vpn-account-controller/src/shared_state.rs b/nym-vpn-core/crates/nym-vpn-account-controller/src/shared_state.rs index c9ce4b2418..a4e4c7f952 100644 --- a/nym-vpn-core/crates/nym-vpn-account-controller/src/shared_state.rs +++ b/nym-vpn-core/crates/nym-vpn-account-controller/src/shared_state.rs @@ -99,6 +99,7 @@ pub enum ReadyToConnect { DeviceRegistrationFailed { message: String, message_id: Option, + code_reference_id: Option, }, //NoCredentialsAvailable, } @@ -321,17 +322,11 @@ pub enum DeviceRegistration { Failed { message: String, message_id: Option, + code_reference_id: Option, }, } impl AccountStateSummary { - //pub fn account_id(&self) -> Option { - // match &self.mnemonic { - // Some(MnemonicState::Stored { id }) => Some(id.clone()), - // _ => None, - // } - //} - pub(crate) fn is_ready_to_register_device(&self) -> ReadyToRegisterDevice { match self.device { Some(DeviceState::NotRegistered) => {} @@ -572,18 +567,22 @@ impl From<&AccountCommandError> for DeviceRegistration { AccountCommandError::UpdateAccountEndpointFailure { message, message_id, + code_reference_id, base_url: _, } | AccountCommandError::UpdateDeviceEndpointFailure { - message_id, message, + message_id, + code_reference_id, } | AccountCommandError::RegisterDeviceEndpointFailure { - message_id, message, + message_id, + code_reference_id, } => DeviceRegistration::Failed { message: message.clone(), message_id: message_id.clone(), + code_reference_id: code_reference_id.clone(), }, AccountCommandError::General(_) | AccountCommandError::Internal(_) @@ -591,6 +590,7 @@ impl From<&AccountCommandError> for DeviceRegistration { | AccountCommandError::NoDeviceStored => DeviceRegistration::Failed { message: err.to_string(), message_id: None, + code_reference_id: None, }, } } diff --git a/nym-vpn-core/crates/nym-vpn-lib/src/platform/error.rs b/nym-vpn-core/crates/nym-vpn-lib/src/platform/error.rs index f9175b92d4..5b26c88b25 100644 --- a/nym-vpn-core/crates/nym-vpn-lib/src/platform/error.rs +++ b/nym-vpn-core/crates/nym-vpn-lib/src/platform/error.rs @@ -51,24 +51,25 @@ pub enum VpnError { #[error("timeout connecting to nym-vpn-api")] VpnApiTimeout, - //#[error("max devices reached: {0}")] - //MaxDevicesReached(u64), #[error("account update failed: {message}")] AccountUpdateFailed { message: String, message_id: Option, + code_reference_id: Option, }, #[error("device update failed: {message}")] DeviceUpdateFailed { message: String, message_id: Option, + code_reference_id: Option, }, #[error("device registration failed: {message}")] DeviceRegistrationFailed { message: String, message_id: Option, + code_reference_id: Option, }, #[error("invalid account storage path: {details}")] @@ -97,9 +98,11 @@ impl From for VpnError { nym_vpn_account_controller::ReadyToConnect::DeviceRegistrationFailed { message, message_id, + code_reference_id, } => Self::DeviceRegistrationFailed { message, message_id, + code_reference_id, }, } } @@ -112,24 +115,30 @@ impl From for VpnError { AccountCommandError::UpdateAccountEndpointFailure { message, message_id, + code_reference_id, base_url: _, } => VpnError::AccountUpdateFailed { message, message_id, + code_reference_id, }, AccountCommandError::UpdateDeviceEndpointFailure { - message_id, message, + message_id, + code_reference_id, } => VpnError::DeviceUpdateFailed { message, message_id, + code_reference_id, }, AccountCommandError::RegisterDeviceEndpointFailure { - message_id, message, + message_id, + code_reference_id, } => VpnError::DeviceRegistrationFailed { message, message_id, + code_reference_id, }, AccountCommandError::NoAccountStored => VpnError::NoAccountStored, AccountCommandError::NoDeviceStored => VpnError::NoDeviceIdentity, diff --git a/nym-vpn-core/crates/nym-vpn-lib/src/uniffi_custom_impls.rs b/nym-vpn-core/crates/nym-vpn-lib/src/uniffi_custom_impls.rs index c0c92a3863..65171b80e3 100644 --- a/nym-vpn-core/crates/nym-vpn-lib/src/uniffi_custom_impls.rs +++ b/nym-vpn-core/crates/nym-vpn-lib/src/uniffi_custom_impls.rs @@ -869,6 +869,7 @@ impl From for Devi nym_vpn_account_controller::shared_state::DeviceRegistration::Failed { message, message_id, + code_reference_id: _, } => DeviceRegistration::Failed { message, message_id, diff --git a/nym-vpn-core/crates/nym-vpnd/src/command_interface/protobuf/account.rs b/nym-vpn-core/crates/nym-vpnd/src/command_interface/protobuf/account.rs index e7259ed266..9452f81993 100644 --- a/nym-vpn-core/crates/nym-vpnd/src/command_interface/protobuf/account.rs +++ b/nym-vpn-core/crates/nym-vpnd/src/command_interface/protobuf/account.rs @@ -136,6 +136,7 @@ fn into_device_registration( nym_vpn_account_controller::shared_state::DeviceRegistration::Failed { message, message_id, + code_reference_id: _, } => { returned_message = Some(message); returned_message_id = message_id; diff --git a/nym-vpn-core/crates/nym-vpnd/src/command_interface/protobuf/error.rs b/nym-vpn-core/crates/nym-vpnd/src/command_interface/protobuf/error.rs index 3a78a07420..e6b7eb33f8 100644 --- a/nym-vpn-core/crates/nym-vpnd/src/command_interface/protobuf/error.rs +++ b/nym-vpn-core/crates/nym-vpnd/src/command_interface/protobuf/error.rs @@ -38,6 +38,7 @@ impl From for nym_vpn_proto::ConnectRequestError { AccountNotReady::UpdateAccount { message, message_id, + code_reference_id: _, } => Self { kind: nym_vpn_proto::connect_request_error::ConnectRequestErrorType::UpdateAccount as i32, @@ -47,6 +48,7 @@ impl From for nym_vpn_proto::ConnectRequestError { AccountNotReady::UpdateDevice { message, message_id, + code_reference_id: _, } => Self { kind: nym_vpn_proto::connect_request_error::ConnectRequestErrorType::UpdateDevice as i32, @@ -56,6 +58,7 @@ impl From for nym_vpn_proto::ConnectRequestError { AccountNotReady::RegisterDevice { message, message_id, + code_reference_id: _, } => Self { kind: nym_vpn_proto::connect_request_error::ConnectRequestErrorType::RegisterDevice as i32, diff --git a/nym-vpn-core/crates/nym-vpnd/src/service/error.rs b/nym-vpn-core/crates/nym-vpnd/src/service/error.rs index 7bc8f70db7..4528521f77 100644 --- a/nym-vpn-core/crates/nym-vpnd/src/service/error.rs +++ b/nym-vpn-core/crates/nym-vpnd/src/service/error.rs @@ -30,18 +30,21 @@ pub enum AccountNotReady { UpdateAccount { message: String, message_id: Option, + code_reference_id: Option, }, #[error("update device failed: {message}")] UpdateDevice { message: String, message_id: Option, + code_reference_id: Option, }, #[error("register device failed: {message}")] RegisterDevice { message: String, message_id: Option, + code_reference_id: Option, }, #[error("no account stored")] @@ -63,24 +66,30 @@ impl From for AccountNotReady { AccountCommandError::UpdateAccountEndpointFailure { message, message_id, + code_reference_id, base_url: _, } => AccountNotReady::UpdateAccount { message, message_id, + code_reference_id, }, AccountCommandError::UpdateDeviceEndpointFailure { - message_id, message, - } => AccountNotReady::UpdateDevice { message_id, + code_reference_id, + } => AccountNotReady::UpdateDevice { message, + message_id, + code_reference_id, }, AccountCommandError::RegisterDeviceEndpointFailure { - message_id, message, + message_id, + code_reference_id, } => AccountNotReady::RegisterDevice { message, message_id, + code_reference_id, }, AccountCommandError::NoAccountStored => AccountNotReady::NoAccountStored, AccountCommandError::NoDeviceStored => AccountNotReady::NoDeviceStored,