From 0f3fbe18193d7075febbc4ffe8c2a3a231734077 Mon Sep 17 00:00:00 2001 From: NerdyPepper Date: Mon, 16 Jul 2018 21:36:15 +0530 Subject: Attempt to remove more panic!s --- Cargo.lock | 7 +++++++ src/content.rs | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ddb4485..fe32c05 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -849,6 +849,7 @@ dependencies = [ "regex 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.8.6 (git+https://github.com/seanmonstar/reqwest)", "serde_json 1.0.20 (git+https://github.com/serde-rs/json)", + "urlencoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1145,6 +1146,11 @@ dependencies = [ "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "urlencoding" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "utf8-ranges" version = "1.0.0" @@ -1362,6 +1368,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" "checksum url 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f808aadd8cfec6ef90e4a14eb46f24511824d1ac596b9682703c87056c8678b7" +"checksum urlencoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3df3561629a8bb4c57e5a2e4c43348d9e29c7c29d9b1c4c1f47166deca8f37ed" "checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122" "checksum uuid 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e1436e58182935dcd9ce0add9ea0b558e8a87befe01c1a301e6020aeb0876363" "checksum vcpkg 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "cbe533e138811704c0e3cbde65a818b35d3240409b4346256c5ede403e082474" diff --git a/src/content.rs b/src/content.rs index b72f4a8..7ebc129 100644 --- a/src/content.rs +++ b/src/content.rs @@ -46,7 +46,7 @@ pub fn get_extract(v: &Value) -> Result { let pageid = &v["query"]["pageids"][0]; let pageid_str = match pageid { Value::String(id) => id, - _ => panic!("wut"), + _ => "-1", }; match &v["query"]["pages"][pageid_str]["extract"] { @@ -57,7 +57,7 @@ pub fn get_extract(v: &Value) -> Result { Ok(format!("{}", extract)) } // ignore non strings - _ => Ok(format!("This page has been deleted or moved")) + _ => Ok(format!("This page does not exist anymore")) } } @@ -100,7 +100,7 @@ pub fn extract_formatter(extract: String) -> StyledString { pub fn get_search_results(search: &str) -> Result, reqwest::Error> { let url = search_url_gen(search); let mut res = reqwest::get(&url[..])?; - let v: Value = serde_json::from_str(&res.text().unwrap()) + let v: Value = serde_json::from_str(&res.text()?) .unwrap_or_else( |e| { panic!("Recieved error {:?}", e); } ); -- cgit v1.2.3