Handle connection errors in a better way
This commit is contained in:
		@@ -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,14 +175,22 @@ 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(()),
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Display game screen
 | 
					        match client {
 | 
				
			||||||
        GameScreen::new(client).show(terminal).await?;
 | 
					            Ok(client) => {
 | 
				
			||||||
 | 
					                // Display game screen
 | 
				
			||||||
 | 
					                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)?;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user