client: Retry failing send()s

This commit is contained in:
George Kaklamanos 2023-05-27 18:15:49 +03:00
parent 02110d9826
commit cf7f54adb5

View file

@ -4,13 +4,15 @@ use spaceapi::Status;
fn get_spaceapi(url: String) -> Status { fn get_spaceapi(url: String) -> Status {
let user_agent = "spaceapi2prometheus"; let user_agent = "spaceapi2prometheus";
let status: Status; let status: Status;
loop {
let client = reqwest::blocking::Client::builder() let client = reqwest::blocking::Client::builder()
.user_agent(user_agent) .user_agent(user_agent)
.build(); .build()
if let Ok(c) = client { .unwrap()
let res = c.get(url).send().unwrap().text().unwrap(); .get(url);
status = serde_json::from_str(&res).unwrap(); loop {
let res = client.try_clone().unwrap().send();
if let Ok(r) = res {
status = serde_json::from_str(&r.text().unwrap()).unwrap();
break; break;
} }
eprintln!("Failed to connect to endpoint, trying again!"); eprintln!("Failed to connect to endpoint, trying again!");