Handle connection errors in a better way

This commit is contained in:
Pierre HUBERT 2022-10-18 09:04:25 +02:00
parent eea2ecbf63
commit 10c099e03b

View File

@ -149,17 +149,17 @@ async fn run_app<B: Backend>(terminal: &mut Terminal<B>) -> Res {
let client = match choice { let client = match choice {
ScreenResult::Ok(SelectPlayModeResult::PlayRandom) => { ScreenResult::Ok(SelectPlayModeResult::PlayRandom) => {
Client::start_random_play(&username).await? Client::start_random_play(&username).await
} }
// Play against bot // Play against bot
ScreenResult::Ok(SelectPlayModeResult::PlayAgainstBot) => { ScreenResult::Ok(SelectPlayModeResult::PlayAgainstBot) => {
Client::start_bot_play(&rules).await? Client::start_bot_play(&rules).await
} }
// Create invite // Create invite
ScreenResult::Ok(SelectPlayModeResult::CreateInvite) => { ScreenResult::Ok(SelectPlayModeResult::CreateInvite) => {
Client::start_create_invite(&rules, &username).await? Client::start_create_invite(&rules, &username).await
} }
// Join invite // Join invite
@ -175,15 +175,23 @@ async fn run_app<B: Backend>(terminal: &mut Terminal<B>) -> Res {
}; };
PopupScreen::new("🔌 Connecting...").show_once(terminal)?; PopupScreen::new("🔌 Connecting...").show_once(terminal)?;
Client::start_accept_invite(code, &username).await? Client::start_accept_invite(code, &username).await
} }
ScreenResult::Canceled | ScreenResult::Ok(SelectPlayModeResult::Exit) => return Ok(()), ScreenResult::Canceled | ScreenResult::Ok(SelectPlayModeResult::Exit) => return Ok(()),
}; };
match client {
Ok(client) => {
// Display game screen // Display game screen
GameScreen::new(client).show(terminal).await?; GameScreen::new(client).show(terminal).await?;
} }
Err(e) => {
log::error!("Failed to connect to server: {}", e);
PopupScreen::new("❌ Failed to connect to server!").show(terminal)?;
}
};
}
} }
#[tokio::main] #[tokio::main]