mirror of
https://github.com/trafficlunar/computer-statistics.git
synced 2026-06-27 22:24:09 +00:00
feat: add notifications when errors
This commit is contained in:
parent
8950e16e70
commit
ce32c1a67e
5 changed files with 1079 additions and 1 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue