Add unknown error

main
kirbylife 2024-09-03 18:48:29 -06:00
parent 9d44c5600a
commit cedfd7a73c
2 changed files with 5 additions and 2 deletions

View File

@ -12,6 +12,7 @@ pub enum InsertionStatus {
LengthError, LengthError,
InvalidChar, InvalidChar,
GameOver, GameOver,
UnknownError,
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@ -83,7 +84,7 @@ impl Game {
(0..=5, _, &GameStatus::Playing, true) => InsertionStatus::LengthError, (0..=5, _, &GameStatus::Playing, true) => InsertionStatus::LengthError,
(0..=5, 5, &GameStatus::Playing, false) => InsertionStatus::InvalidChar, (0..=5, 5, &GameStatus::Playing, false) => InsertionStatus::InvalidChar,
(_, _, &GameStatus::Win(_) | &GameStatus::Fail, _) => InsertionStatus::GameOver, (_, _, &GameStatus::Win(_) | &GameStatus::Fail, _) => InsertionStatus::GameOver,
_ => todo!(), _ => InsertionStatus::UnknownError,
}; };
self.last_insertion_status = insertion_status.clone(); self.last_insertion_status = insertion_status.clone();
insertion_status insertion_status

View File

@ -108,7 +108,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
} }
InsertionStatus::LengthError => { InsertionStatus::LengthError => {
Some("La palabra debe de ser de 5 letras".to_string()) Some("La palabra debe de ser de 5 letras".to_string())
} },
InsertionStatus::UnknownError => Some("A chinga', error inesperado.".to_string())
}; };
result_pattern = None; result_pattern = None;
} }
@ -149,6 +150,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.mount("/:uuid/:attempt", move |request| async move { .mount("/:uuid/:attempt", move |request| async move {
let mut context = tera::Context::new(); let mut context = tera::Context::new();
// This should be safe because you can only get into the route with the right path
let possible_uuid = request.parameters.get("uuid").unwrap(); let possible_uuid = request.parameters.get("uuid").unwrap();
let attempt = urlencoding::decode(request.parameters.get("attempt").unwrap()).unwrap().to_string(); let attempt = urlencoding::decode(request.parameters.get("attempt").unwrap()).unwrap().to_string();