Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code_reference_id to vpn api error #1597

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,22 @@ pub enum AccountCommandError {
UpdateAccountEndpointFailure {
message: String,
message_id: Option<String>,
code_reference_id: Option<String>,
base_url: Box<url::Url>,
},

#[error("failed to update device state: {message}")]
UpdateDeviceEndpointFailure {
message_id: Option<String>,
message: String,
message_id: Option<String>,
code_reference_id: Option<String>,
},

#[error("failed to register device: {message}")]
RegisterDeviceEndpointFailure {
message_id: Option<String>,
message: String,
message_id: Option<String>,
code_reference_id: Option<String>,
},

#[error("no account stored")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ pub enum ReadyToConnect {
DeviceRegistrationFailed {
message: String,
message_id: Option<String>,
code_reference_id: Option<String>,
},
//NoCredentialsAvailable,
}
Expand Down Expand Up @@ -321,17 +322,11 @@ pub enum DeviceRegistration {
Failed {
message: String,
message_id: Option<String>,
code_reference_id: Option<String>,
},
}

impl AccountStateSummary {
//pub fn account_id(&self) -> Option<String> {
// 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) => {}
Expand Down Expand Up @@ -572,25 +567,30 @@ 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(_)
| AccountCommandError::NoAccountStored
| AccountCommandError::NoDeviceStored => DeviceRegistration::Failed {
message: err.to_string(),
message_id: None,
code_reference_id: None,
},
}
}
Expand Down
17 changes: 13 additions & 4 deletions nym-vpn-core/crates/nym-vpn-lib/src/platform/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
code_reference_id: Option<String>,
},

#[error("device update failed: {message}")]
DeviceUpdateFailed {
message: String,
message_id: Option<String>,
code_reference_id: Option<String>,
},

#[error("device registration failed: {message}")]
DeviceRegistrationFailed {
message: String,
message_id: Option<String>,
code_reference_id: Option<String>,
},

#[error("invalid account storage path: {details}")]
Expand Down Expand Up @@ -97,9 +98,11 @@ impl From<nym_vpn_account_controller::ReadyToConnect> for VpnError {
nym_vpn_account_controller::ReadyToConnect::DeviceRegistrationFailed {
message,
message_id,
code_reference_id,
} => Self::DeviceRegistrationFailed {
message,
message_id,
code_reference_id,
},
}
}
Expand All @@ -112,24 +115,30 @@ impl From<nym_vpn_account_controller::AccountCommandError> 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,
Expand Down
1 change: 1 addition & 0 deletions nym-vpn-core/crates/nym-vpn-lib/src/uniffi_custom_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,7 @@ impl From<nym_vpn_account_controller::shared_state::DeviceRegistration> for Devi
nym_vpn_account_controller::shared_state::DeviceRegistration::Failed {
message,
message_id,
code_reference_id: _,
} => DeviceRegistration::Failed {
message,
message_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ impl From<AccountNotReady> 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,
Expand All @@ -47,6 +48,7 @@ impl From<AccountNotReady> 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,
Expand All @@ -56,6 +58,7 @@ impl From<AccountNotReady> 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,
Expand Down
15 changes: 12 additions & 3 deletions nym-vpn-core/crates/nym-vpnd/src/service/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,21 @@ pub enum AccountNotReady {
UpdateAccount {
message: String,
message_id: Option<String>,
code_reference_id: Option<String>,
},

#[error("update device failed: {message}")]
UpdateDevice {
message: String,
message_id: Option<String>,
code_reference_id: Option<String>,
},

#[error("register device failed: {message}")]
RegisterDevice {
message: String,
message_id: Option<String>,
code_reference_id: Option<String>,
},

#[error("no account stored")]
Expand All @@ -63,24 +66,30 @@ impl From<AccountCommandError> 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,
Expand Down
Loading