Refactorings/fixes for back-end

This commit is contained in:
Stephen Seo 2022-03-16 12:31:18 +09:00
parent e1180963f3
commit 97ca4adecc
2 changed files with 3 additions and 13 deletions

View file

@ -10,9 +10,7 @@ pub fn handle_json(root: Value) -> Result<String, String> {
"disconnect" => handle_disconnect(root), "disconnect" => handle_disconnect(root),
"request_board_state" => handle_request_board_state(root), "request_board_state" => handle_request_board_state(root),
"game_state" => handle_game_state(root), "game_state" => handle_game_state(root),
_ => { _ => Err("{\"type\":\"invalid_type\"}".into()),
Err("{\"type\":\"invalid_type\"}".into())
}
} }
} else { } else {
Err("{\"type\":\"invalid_json\"}".into()) Err("{\"type\":\"invalid_json\"}".into())

View file

@ -9,16 +9,8 @@ async fn main() {
.and(warp::body::json()) .and(warp::body::json())
.map(|json_value: Value| { .map(|json_value: Value| {
let result = json_handlers::handle_json(json_value); let result = json_handlers::handle_json(json_value);
if let Ok(result_str) = result { result.unwrap_or_else(|e| e)
result_str
} else if let Err(error_str) = result {
error_str
} else {
unreachable!()
}
}); });
warp::serve(route) warp::serve(route).run(([0, 0, 0, 0], 1237)).await;
.run(([0,0,0,0], 1237))
.await;
} }