no unwraps! (except on locks)

This commit is contained in:
Adam 2024-07-21 23:28:06 -04:00
parent 6636920752
commit a596932aed

View file

@ -1,6 +1,7 @@
use crate::api::{greeting, Message, User};
use crate::AppState;
use crate::Arc;
use anyhow::Result;
use lib::models::*;
pub async fn message_handler(message: Message, state: &Arc<AppState>, who: &User) {
@ -12,9 +13,12 @@ pub async fn message_handler(message: Message, state: &Arc<AppState>, who: &User
tracing::debug!("New game request received.");
// create game
if let Ok(new_game_object) = Game::new(new_game) {
let game_json = serde_json::to_string(&new_game_object).unwrap();
if let Ok(game_json) = serde_json::to_string(&new_game_object) {
tracing::debug!("Sent new game JSON.");
let _ = tx.send(game_json);
} else {
tracing::error!("Failed to convert Game object to JSON.")
}
state.games.lock().unwrap().push(new_game_object);
let _update = tx.send(greeting(state));
} else {