diff mbox series

[4/8] Jenkins: Try again instead of panic if API call fails

Message ID 20180720115728.19312-4-ruscur@russell.cc
State Accepted
Headers show
Series [1/8] Convert from hyper to reqwest | expand

Commit Message

Russell Currey July 20, 2018, 11:57 a.m. UTC
Signed-off-by: Russell Currey <ruscur@russell.cc>
---
 src/jenkins.rs | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

Andrew Donnellan July 23, 2018, 12:58 a.m. UTC | #1
On 20/07/18 21:57, Russell Currey wrote:
> Signed-off-by: Russell Currey <ruscur@russell.cc>

This could probably do with a timeout... as could everything else in 
this function though, so:

Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
diff mbox series

Patch

diff --git a/src/jenkins.rs b/src/jenkins.rs
index 0e7cdbc..987fae9 100644
--- a/src/jenkins.rs
+++ b/src/jenkins.rs
@@ -111,7 +111,14 @@  impl JenkinsBackend {
         let url = format!("{}api/json", base_url);
         let mut result_str = String::new();
         loop {
-            let mut resp = self.get_url(&url).expect("HTTP request error");
+            let mut resp = match self.get_url(&url) {
+                Ok(r) => r,
+                Err(e) => {
+                    warn!("Couldn't hit Jenkins API: {}", e);
+                    sleep(Duration::from_millis(JENKINS_POLLING_INTERVAL));
+                    continue;
+                }
+            };
 
             if resp.status().is_server_error() {
                 sleep(Duration::from_millis(JENKINS_POLLING_INTERVAL));