Display errors from 'send'.
authorGrégory Burri <gregory.burri@matisa.ch>
Wed, 9 Sep 2020 07:17:32 +0000 (09:17 +0200)
committerGrégory Burri <gregory.burri@matisa.ch>
Wed, 9 Sep 2020 07:17:32 +0000 (09:17 +0200)
Cargo.lock
src/main.rs

index a12ebec..bec856e 100644 (file)
@@ -591,9 +591,9 @@ checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"
 
 [[package]]
 name = "js-sys"
-version = "0.3.44"
+version = "0.3.45"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "85a7e2c92a4804dd459b86c339278d0fe87cf93757fae222c3fa3ae75458bc73"
+checksum = "ca059e81d9486668f12d455a4ea6daa600bd408134cd17e3d3fb5a32d1f016f8"
 dependencies = [
  "wasm-bindgen",
 ]
@@ -763,9 +763,9 @@ dependencies = [
 
 [[package]]
 name = "net2"
-version = "0.2.34"
+version = "0.2.35"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2ba7c918ac76704fb42afcbbb43891e72731f3dcca3bef2a19786297baf14af7"
+checksum = "3ebc3ec692ed7c9a255596c67808dee269f64655d8baf7b4f0638e51ba1d6853"
 dependencies = [
  "cfg-if",
  "libc",
@@ -1566,9 +1566,9 @@ dependencies = [
 
 [[package]]
 name = "tracing-core"
-version = "0.1.15"
+version = "0.1.16"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4f0e00789804e99b20f12bc7003ca416309d28a6f495d6af58d1e2c2842461b5"
+checksum = "5bcf46c1f1f06aeea2d6b81f3c863d0930a596c86ad1920d4e5bad6dd1d7119a"
 dependencies = [
  "lazy_static",
 ]
@@ -1686,9 +1686,9 @@ checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
 
 [[package]]
 name = "wasm-bindgen"
-version = "0.2.67"
+version = "0.2.68"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f0563a9a4b071746dd5aedbc3a28c6fe9be4586fb3fbadb67c400d4f53c6b16c"
+checksum = "1ac64ead5ea5f05873d7c12b545865ca2b8d28adfc50a49b84770a3a97265d42"
 dependencies = [
  "cfg-if",
  "serde",
@@ -1698,9 +1698,9 @@ dependencies = [
 
 [[package]]
 name = "wasm-bindgen-backend"
-version = "0.2.67"
+version = "0.2.68"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bc71e4c5efa60fb9e74160e89b93353bc24059999c0ae0fb03affc39770310b0"
+checksum = "f22b422e2a757c35a73774860af8e112bff612ce6cb604224e8e47641a9e4f68"
 dependencies = [
  "bumpalo",
  "lazy_static",
@@ -1713,9 +1713,9 @@ dependencies = [
 
 [[package]]
 name = "wasm-bindgen-futures"
-version = "0.4.17"
+version = "0.4.18"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "95f8d235a77f880bcef268d379810ea6c0af2eacfa90b1ad5af731776e0c4699"
+checksum = "b7866cab0aa01de1edf8b5d7936938a7e397ee50ce24119aef3e1eaa3b6171da"
 dependencies = [
  "cfg-if",
  "js-sys",
@@ -1725,9 +1725,9 @@ dependencies = [
 
 [[package]]
 name = "wasm-bindgen-macro"
-version = "0.2.67"
+version = "0.2.68"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "97c57cefa5fa80e2ba15641578b44d36e7a64279bc5ed43c6dbaf329457a2ed2"
+checksum = "6b13312a745c08c469f0b292dd2fcd6411dba5f7160f593da6ef69b64e407038"
 dependencies = [
  "quote",
  "wasm-bindgen-macro-support",
@@ -1735,9 +1735,9 @@ dependencies = [
 
 [[package]]
 name = "wasm-bindgen-macro-support"
-version = "0.2.67"
+version = "0.2.68"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "841a6d1c35c6f596ccea1f82504a192a60378f64b3bb0261904ad8f2f5657556"
+checksum = "f249f06ef7ee334cc3b8ff031bfc11ec99d00f34d86da7498396dc1e3b1498fe"
 dependencies = [
  "proc-macro2",
  "quote",
@@ -1748,15 +1748,15 @@ dependencies = [
 
 [[package]]
 name = "wasm-bindgen-shared"
-version = "0.2.67"
+version = "0.2.68"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "93b162580e34310e5931c4b792560108b10fd14d64915d7fff8ff00180e70092"
+checksum = "1d649a3145108d7d3fbcde896a468d1bd636791823c9921135218ad89be08307"
 
 [[package]]
 name = "web-sys"
-version = "0.3.44"
+version = "0.3.45"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "dda38f4e5ca63eda02c059d243aa25b5f35ab98451e518c51612cd0f1bd19a47"
+checksum = "4bf6ef87ad7ae8008e15a355ce696bed26012b7caa21605188cfd8214ab51e2d"
 dependencies = [
  "js-sys",
  "wasm-bindgen",
index 9eca649..aeafb57 100644 (file)
@@ -51,35 +51,39 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
 
     loop {
         println!("Request: {}", url);
-        let resp = client.get(&url).send()?;
-
-        if resp.status().is_success() {
-            let html = resp.text()?;
-            let document = Html::parse_document(&html);
-
-            // A vector of (<title>, <url>), empty if nothing matches.
-            let match_items: Vec<(String, String)> =
-                document.select(&selector).filter_map(
-                    |element| {
-                        if let (Some(title), Some(url_to_item)) = (element.value().attr("title"), element.value().attr("href")) {
-                            if title.find(to_match).is_some() {
-                                return Some((String::from(title), String::from(url_to_item)))
+
+        match client.get(&url).send() {
+            Ok(resp) =>
+                if resp.status().is_success() {
+                    let html = resp.text()?;
+                    let document = Html::parse_document(&html);
+
+                    // A vector of (<title>, <url>), empty if nothing matches.
+                    let match_items: Vec<(String, String)> =
+                        document.select(&selector).filter_map(
+                            |element| {
+                                if let (Some(title), Some(url_to_item)) = (element.value().attr("title"), element.value().attr("href")) {
+                                    if title.find(to_match).is_some() {
+                                        return Some((String::from(title), String::from(url_to_item)))
+                                    }
+                                }
+                                None
                             }
-                        }
-                        None
+                        ).collect();
+
+                    if match_items.is_empty() {
+                        println!("No matches...");
+                    } else if send_email(&match_items[..], &config.smtp_login, &config.smtp_password) {
+                        println!("Some matches has been found! An e-mail has been sent!");
+                        return Ok(())
+                    } else {
+                        println!("Unable to send e-mail");
                     }
-                ).collect();
-
-            if match_items.is_empty() {
-                println!("No matches...");
-            } else if send_email(&match_items[..], &config.smtp_login, &config.smtp_password) {
-                println!("Some matches has been found! An e-mail has been sent!");
-                return Ok(())
-            } else {
-                println!("Unable to send e-mail");
-            }
-        } else {
-            println!("Request unsuccessful:\n{:#?}", resp);
+                } else {
+                    println!("Request unsuccessful:\n{:#?}", resp);
+                },
+            Err(error) =>
+                println!("Error during request: {:?}", error)
         }
 
         thread::sleep(time::Duration::from_secs(60)); // 1 min.