Skip to content

Commit

Permalink
show error when wttr.in is broken, fixes #55, fixes #66
Browse files Browse the repository at this point in the history
  • Loading branch information
Yo'av Moshe committed Oct 27, 2024
1 parent 6c04f08 commit eca4a1a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
[package]
name = "wttrbar"
version = "0.10.6"
version = "0.10.7"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
chrono = "0.4.34"
clap = { version = "4.5.1", features = ["derive"] }
reqwest = { version = "0.11.24", default-features = false, features = ["blocking", "json", "rustls-tls"] }
reqwest = { version = "0.11.24", default-features = false, features = [
"blocking",
"json",
"rustls-tls",
] }
serde_json = "1.0.96"

8 changes: 7 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@ fn main() {
} else {
loop {
match client.get(&weather_url).send() {
Ok(response) => break response.json::<Value>().unwrap(),
Ok(response) => match response.json::<Value>() {
Ok(json) => break json,
Err(_) => {
println!("{{\"text\":\"⛓️‍💥\", \"tooltip\":\"invalid wttr.in response\"}}");
exit(0)
}
},
Err(_) => {
iterations += 1;
thread::sleep(time::Duration::from_millis(500 * iterations));
Expand Down

0 comments on commit eca4a1a

Please sign in to comment.