Skip to content

Commit

Permalink
Report the failure when the server is down
Browse files Browse the repository at this point in the history
  • Loading branch information
ilpianista committed Nov 26, 2019
1 parent 10fc117 commit fa0af03
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ use std::str;
mod avg;
mod enums;

const WEBSITE: &str = "https://security.archlinux.org";

struct Options {
format: Option<String>,
quiet: u64,
Expand Down Expand Up @@ -58,10 +60,12 @@ fn main() {
let mut avgs = String::new();
{
info!("Downloading AVGs...");
let avgs_url = "https://security.archlinux.org/issues/all.json";
let avgs_url = format!("{}/issues/all.json", WEBSITE);

let mut easy = Easy::new();
easy.url(avgs_url).expect("curl::Easy::url failed");
easy.fail_on_error(true)
.expect("curl::Easy::fail_on_error failed");
easy.url(&avgs_url).expect("curl::Easy::url failed");
let mut transfer = easy.transfer();
transfer
.write_function(|data| {
Expand All @@ -72,7 +76,10 @@ fn main() {
match transfer.perform() {
Ok(_) => {}
Err(_) => {
println!("Cannot fetch data, please check your network connection!");
println!(
"Cannot fetch data from {}, please check your network connection!",
WEBSITE
);
exit(1)
}
};
Expand Down

0 comments on commit fa0af03

Please sign in to comment.