Skip to content

Commit

Permalink
add error handler for api
Browse files Browse the repository at this point in the history
  • Loading branch information
zefanjajobse committed Sep 22, 2023
1 parent 1fbd9ad commit b47a032
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
44 changes: 28 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fn main() {
message_timeout_mins: 8,
game: structs::Games::from("bf1"),
launcher: structs::Launchers::from("ea_desktop"),
endpoint: "https://manager-api.gametools.network".into()
endpoint: "https://manager-api.gametools.network".into(),
};
cfg.game_location = actions::game::find_game(&cfg);
cfg.link2ea_location = actions::launchers::find_link2ea();
Expand Down Expand Up @@ -122,21 +122,33 @@ fn main() {
.timeout(Duration::new(10, 0))
.call()
{
Ok(response) => match response.into_json::<structs::CurrentServer>() {
Ok(seeder_info) => {
functions::seed_server::start(
seeder_info,
&mut old_seeder_info,
&cfg,
&game_running,
&retry_launch,
&message_running_clone,
);
}
Err(e) => {
log::error!("Failed to get info about server to join: {}", e);
log::info!("reconnecting...");
}
Ok(response) => match response.header("type") {
Some(_) => match response.into_json::<structs::Error>() {
Ok(error_return) => {
log::error!("Error: {}", error_return.error);
log::info!("retrying...");
}
Err(e) => {
log::error!("Incorrect error return: {}", e);
log::info!("retrying...");
}
},
None => match response.into_json::<structs::CurrentServer>() {
Ok(seeder_info) => {
functions::seed_server::start(
seeder_info,
&mut old_seeder_info,
&cfg,
&game_running,
&retry_launch,
&message_running_clone,
);
}
Err(e) => {
log::error!("Failed to get info about server to join: {}", e);
log::info!("reconnecting...");
}
},
},
Err(e) => {
log::error!("Failed to connect to backend: {}", e);
Expand Down
7 changes: 6 additions & 1 deletion src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ pub struct CurrentServer {
pub rejoin: bool,
}

#[derive(Deserialize, PartialEq, Eq, Clone, Debug)]
pub struct Error {
pub error: String,
}

#[derive(Debug)]
pub struct GameInfo {
pub is_running: bool,
Expand All @@ -71,7 +76,7 @@ impl ::std::default::Default for SeederConfig {
message_timeout_mins: 8,
game: Games::from("bf1"),
launcher: Launchers::from("ea_desktop"),
endpoint: "https://manager-api.gametools.network".into()
endpoint: "https://manager-api.gametools.network".into(),
};
cfg.game_location = actions::game::find_game(&cfg);
cfg.link2ea_location = actions::launchers::find_link2ea();
Expand Down

0 comments on commit b47a032

Please sign in to comment.