diff --git a/src/app/service.rs b/src/app/service.rs index 114fff2..7ca1a10 100644 --- a/src/app/service.rs +++ b/src/app/service.rs @@ -21,22 +21,22 @@ pub fn new( } impl Service { - pub fn alert_on_threshold_violation(&self) { + pub fn alert_on_threshold_violation(&self) -> Result<(), Box> { // Check for threshold violations and send alerts let violations = self.monitor.check_thresholds(); for violation in violations { let message = self.formatter.format_violation(violation); - self.notifier - .send_notification(&message) - .expect("Failed to send notification"); + self.notifier.send_notification(&message)?; } + + Ok(()) } - pub fn send_all_metrics_notification(&self) { + pub fn send_all_metrics_notification(&self) -> Result<(), Box> { // Send a final notification with all system information let summary = self.formatter.format_summary(&self.monitor.get_metrics()); - self.notifier - .send_notification(&summary) - .expect("Failed to send final notification"); + self.notifier.send_notification(&summary)?; + + Ok(()) } } diff --git a/src/main.rs b/src/main.rs index 852922a..d1c52b8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -45,6 +45,12 @@ fn main() { Box::new(system_monitor_adapter), Box::new(formatter), ); - service.alert_on_threshold_violation(); - service.send_all_metrics_notification(); + + if let Err(e) = service.alert_on_threshold_violation() { + eprintln!("Error during threshold violation check: {}", e); + } + + if let Err(e) = service.send_all_metrics_notification() { + eprintln!("Error sending final notification: {}", e); + } }