Skip to content

Commit

Permalink
Fail silently when pulling stargates in batch
Browse files Browse the repository at this point in the history
  • Loading branch information
madmikeross committed Dec 21, 2023
1 parent b278ba2 commit b7ce814
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
12 changes: 6 additions & 6 deletions src/esi.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use chrono::{DateTime, Utc};
use reqwest::{Client, Response};
use reqwest::{Client, Error, Response};
use serde::{Deserialize, Serialize};

#[derive(Debug, Deserialize)]
Expand Down Expand Up @@ -48,7 +48,7 @@ pub struct Destination {
pub async fn get_system_details(
client: &Client,
system_id: i64,
) -> Result<SystemEsiResponse, reqwest::Error> {
) -> Result<SystemEsiResponse, Error> {
let system_detail_url = format!(
"https://esi.evetech.net/latest/universe/systems/{}",
system_id
Expand All @@ -60,7 +60,7 @@ pub async fn get_system_details(
pub async fn get_stargate_details(
client: &Client,
stargate_id: i64,
) -> Result<StargateEsiResponse, reqwest::Error> {
) -> Result<StargateEsiResponse, Error> {
let stargate_url = format!(
"https://esi.evetech.net/latest/universe/stargates/{}",
stargate_id
Expand All @@ -69,7 +69,7 @@ pub async fn get_stargate_details(
response.json().await
}

pub async fn get_system_ids(client: &Client) -> Result<Vec<i64>, reqwest::Error> {
pub async fn get_system_ids(client: &Client) -> Result<Vec<i64>, Error> {
let systems_url = "https://esi.evetech.net/latest/universe/systems/";
let response = client.get(systems_url).send().await?;
response.json().await
Expand All @@ -89,7 +89,7 @@ pub struct SystemKills {
pub system_id: i64,
}

pub async fn get_system_kills(client: &Client) -> Result<SystemKillsResponse, reqwest::Error> {
pub async fn get_system_kills(client: &Client) -> Result<SystemKillsResponse, Error> {
let system_kills_url = "https://esi.evetech.net/latest/universe/system_kills/";
let response = client.get(system_kills_url).send().await?;
let last_modified = get_last_modified_date(&response);
Expand Down Expand Up @@ -128,7 +128,7 @@ pub struct SystemJumps {
pub system_id: i64,
}

pub async fn get_system_jumps(client: &Client) -> Result<SystemJumpsResponse, reqwest::Error> {
pub async fn get_system_jumps(client: &Client) -> Result<SystemJumpsResponse, Error> {
let system_jumps_url = "https://esi.evetech.net/latest/universe/system_jumps/";
let response = client.get(system_jumps_url).send().await?;
let last_modified = get_last_modified_date(&response);
Expand Down
19 changes: 13 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ async fn stargates_refresh_handler(
client: Client,
graph: Arc<Graph>,
) -> Result<impl Reply, Rejection> {
pull_all_stargates(client, graph).await.unwrap();
pull_all_stargates(client, graph).await?;
Ok(reply())
}

Expand Down Expand Up @@ -414,11 +414,18 @@ async fn pull_stargate(
graph: Arc<Graph>,
stargate_id: i64,
) -> Result<(), ReplicationError> {
let stargate_response = get_stargate_details(&client, stargate_id).await?;
let stargate = Stargate::from(stargate_response);
save_stargate(graph.clone(), &stargate)
.await
.map_err(TargetError)
match get_stargate_details(&client, stargate_id).await {
Ok(response) => {
let stargate = Stargate::from(response);
save_stargate(graph.clone(), &stargate)
.await
.map_err(TargetError)
}
Err(_) => {
println!("Failed to pull stargate {}", stargate_id);
Ok(()) // Temporarily allow this to not error so that other stargate pulls can succeed.
}
}
}

#[cfg(test)]
Expand Down

0 comments on commit b7ce814

Please sign in to comment.