Skip to content

Commit

Permalink
report properly registration errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Dec 8, 2023
1 parent 3d2aad1 commit 5a8cba6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 2 additions & 0 deletions rust/agama-lib/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub enum ServiceError {
Anyhow(#[from] anyhow::Error),
#[error("Wrong user parameters: '{0:?}'")]
WrongUser(Vec<String>),
#[error("Registration failed: '{0}'")]
FailedRegistration(String),
#[error("Error: {0}")]
UnsuccessfulAction(String),
}
Expand Down
5 changes: 2 additions & 3 deletions rust/agama-lib/src/product/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,11 @@ impl<'a> ProductClient<'a> {
}

/// register product
pub async fn register(&self, code: &str, email: &str) -> Result<(), ServiceError> {
pub async fn register(&self, code: &str, email: &str) -> Result<(u32, String), ServiceError> {
let mut options: HashMap<&str, zbus::zvariant::Value> = HashMap::new();
if !email.is_empty() {
options.insert("Email", zbus::zvariant::Value::new(email));
}
self.registration_proxy.register(code, options).await?;
Ok(())
Ok(self.registration_proxy.register(code, options).await?)
}
}
8 changes: 6 additions & 2 deletions rust/agama-lib/src/product/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@ impl<'a> ProductStore<'a> {
}
}
if let Some(reg_code) = &settings.registration_code {
let (result, message);
if let Some(email) = &settings.registration_email {
self.product_client.register(reg_code, email).await?;
(result, message) = self.product_client.register(reg_code, email).await?;
} else {
self.product_client.register(reg_code, "").await?;
(result, message) = self.product_client.register(reg_code, "").await?;
};
if result != 0 {
return Err(ServiceError::FailedRegistration(message));
}
probe = true;
}
Expand Down

0 comments on commit 5a8cba6

Please sign in to comment.