From 41b3dc5739a6a39748483927c4af34a3abdc1a02 Mon Sep 17 00:00:00 2001 From: spikecodes <19519553+spikecodes@users.noreply.github.com> Date: Wed, 11 Aug 2021 20:49:42 -0700 Subject: [PATCH] More apt error messages for Reddit outages --- Cargo.lock | 26 +++++++++++++------------- Cargo.toml | 2 +- src/client.rs | 10 +++++++++- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index be16bd9..47703f6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -109,9 +109,9 @@ checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" [[package]] name = "bitflags" -version = "1.2.1" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +checksum = "2da1976d75adbe5fbc88130ecd119529cf1cc6a93ae1546d8696ee66f0d21af1" [[package]] name = "bitvec" @@ -154,9 +154,9 @@ dependencies = [ [[package]] name = "cached_proc_macro" -version = "0.6.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf857ae42d910aede5c5186e62684b0d7a597ce2fe3bd14448ab8f7ef439848c" +checksum = "25a685ba39b57a91a53d149dcbef854f50fbe204d1ff6081ea0bec3529a0c456" dependencies = [ "async-mutex", "cached_proc_macro_types", @@ -475,9 +475,9 @@ dependencies = [ [[package]] name = "http-body" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60daa14be0e0786db0f03a9e57cb404c9d756eed2b6c62b9ea98ec5743ec75a9" +checksum = "399c583b2979440c60be0821a6199eca73bc3c8dcd9d070d75ac726e2c6186e5" dependencies = [ "bytes", "http", @@ -609,13 +609,13 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.98" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "320cfe77175da3a483efed4bc0adc1968ca050b098ce4f2f1c13a56626128790" +checksum = "a7f823d141fe0a24df1e23b4af4e3c7ba9e5966ec514ea068c93024aa7deb765" [[package]] name = "libreddit" -version = "0.14.13" +version = "0.14.14" dependencies = [ "askama", "async-recursion", @@ -817,9 +817,9 @@ checksum = "941ba9d78d8e2f7ce474c015eea4d9c6d25b6a3327f9832ee29a4de27f91bbb8" [[package]] name = "redox_syscall" -version = "0.2.9" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ab49abadf3f9e1c4bc499e8845e152ad87d2ad2d30371841171169e9d75feee" +checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" dependencies = [ "bitflags", ] @@ -1014,9 +1014,9 @@ dependencies = [ [[package]] name = "slab" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f173ac3d1a7e3b28003f40de0b5ce7fe2710f9b9dc3fc38664cebee46b3b6527" +checksum = "c307a32c1c5c437f38c7fd45d753050587732ba8628319fbdf12a7e289ccc590" [[package]] name = "smallvec" diff --git a/Cargo.toml b/Cargo.toml index 32b3b5d..cea93a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "libreddit" description = " Alternative private front-end to Reddit" license = "AGPL-3.0" repository = "https://github.com/spikecodes/libreddit" -version = "0.14.13" +version = "0.14.14" authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"] edition = "2018" diff --git a/src/client.rs b/src/client.rs index 7dd5b39..aa70228 100644 --- a/src/client.rs +++ b/src/client.rs @@ -122,6 +122,8 @@ pub async fn json(path: String, quarantine: bool) -> Result { // Fetch the url... match request(url.clone(), quarantine).await { Ok(response) => { + let status = response.status(); + // asynchronously aggregate the chunks of the body match hyper::body::aggregate(response).await { Ok(body) => { @@ -146,7 +148,13 @@ pub async fn json(path: String, quarantine: bool) -> Result { Ok(json) } } - Err(e) => err("Failed to parse page JSON data", e.to_string()), + Err(e) => { + if status.is_server_error() { + Err("Reddit is having issues, check if there's an outage".to_string()) + } else { + err("Failed to parse page JSON data", e.to_string()) + } + } } } Err(e) => err("Failed receiving body from Reddit", e.to_string()),