feat: add notifications when errors
This commit is contained in:
parent
8950e16e70
commit
ce32c1a67e
5 changed files with 1079 additions and 1 deletions
1061
Cargo.lock
generated
1061
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -5,4 +5,5 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
dotenvy = "0.15.7"
|
||||
notify-rust = "4.11.3"
|
||||
tungstenite = "0.24.0"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use std::error::Error;
|
||||
|
||||
mod websocket;
|
||||
mod notifications;
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
dotenvy::dotenv()?;
|
||||
|
|
|
|||
11
src/notifications.rs
Normal file
11
src/notifications.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
use notify_rust::Notification;
|
||||
|
||||
pub fn send_error_notification(body: &str) {
|
||||
Notification::new()
|
||||
.summary("Computer Statistics Error")
|
||||
.body(body)
|
||||
.icon("dialog-error")
|
||||
.timeout(0)
|
||||
.show()
|
||||
.unwrap();
|
||||
}
|
||||
|
|
@ -2,11 +2,15 @@ use std::{env, net::TcpStream};
|
|||
|
||||
use tungstenite::{stream::MaybeTlsStream, Message, WebSocket};
|
||||
|
||||
use crate::notifications;
|
||||
|
||||
pub fn connect() -> Result<WebSocket<MaybeTlsStream<TcpStream>>, tungstenite::Error> {
|
||||
let (socket, _) = match tungstenite::connect(env::var("WEBSOCKET_URL").unwrap()) {
|
||||
Ok(ws) => ws,
|
||||
Err(err) => {
|
||||
eprintln!("Unable to connect to WebSocket");
|
||||
eprintln!("Unable to connect to WebSocket: {}", err);
|
||||
notifications::send_error_notification("Unable to connect to WebSocket");
|
||||
|
||||
return Err(err);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue