From 6ec0c444f642630485ca18b3043191b67a6f8e8c Mon Sep 17 00:00:00 2001 From: Jokler Date: Sat, 12 May 2018 00:21:59 +0200 Subject: Factoids: Improve display of runtime errors in lua --- src/plugins/factoids/utils.rs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src/plugins/factoids/utils.rs') diff --git a/src/plugins/factoids/utils.rs b/src/plugins/factoids/utils.rs index fd08da1..89f5d6c 100644 --- a/src/plugins/factoids/utils.rs +++ b/src/plugins/factoids/utils.rs @@ -3,20 +3,29 @@ extern crate reqwest; use std::thread; use std::time::Duration; -use super::rlua::prelude::*; +use super::rlua::Error as LuaError; +use super::rlua::Lua; use utils::Url; +use utils::error::ErrorKind::Connection; -use self::LuaError::RuntimeError; +use failure::Fail; pub fn download(_: &Lua, url: String) -> Result { let url = Url::from(url).max_kib(1024); match url.request() { Ok(v) => Ok(v), - Err(e) => Err(RuntimeError(format!( - "Failed to download {} - {}", - url.as_str(), - e.to_string() - ))), + Err(e) => { + let error = match e.kind() { + Connection => e.cause().unwrap().to_string(), + _ => e.to_string(), + }; + + Err(LuaError::RuntimeError(format!( + "Failed to download {} - {}", + url.as_str(), + error + ))) + } } } -- cgit v1.2.3-70-g09d2