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 {
let user_agent = "spaceapi2prometheus";
let status: Status;
let client = reqwest::blocking::Client::builder()
.user_agent(user_agent)
.build()
.unwrap()
.get(url);
loop {
let client = reqwest::blocking::Client::builder()
.user_agent(user_agent)
.build();
if let Ok(c) = client {
let res = c.get(url).send().unwrap().text().unwrap();
status = serde_json::from_str(&res).unwrap();
let res = client.try_clone().unwrap().send();
if let Ok(r) = res {
status = serde_json::from_str(&r.text().unwrap()).unwrap();
break;
}
eprintln!("Failed to connect to endpoint, trying again!");