From 8d32f8b3f3bdaab19e45141f33b8ac76c6a81fed Mon Sep 17 00:00:00 2001 From: Stan Rozenraukh Date: Mon, 25 May 2020 03:25:41 -0400 Subject: [PATCH] Fix panic in load_data(url=%s) (#1036) If there is no response from the server, `load_data` would panic with: `response status`. This patch removes the `expect` in favor of an error message that we couldn't get a response from the server for a given url. --- components/templates/src/global_fns/load_data.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/components/templates/src/global_fns/load_data.rs b/components/templates/src/global_fns/load_data.rs index 8aa542da..7432a6c0 100644 --- a/components/templates/src/global_fns/load_data.rs +++ b/components/templates/src/global_fns/load_data.rs @@ -210,11 +210,10 @@ impl TeraFn for LoadData { .send() .and_then(|res| res.error_for_status()) .map_err(|e| { - format!( - "Failed to request {}: {}", - url, - e.status().expect("response status") - ) + match e.status() { + Some(status) => format!("Failed to request {}: {}", url, status), + None => format!("Could not get response status for url: {}", url), + } })?; response .text()