From ee396d7c5b45d0dea4160f5cef0f0bc81980dd1f Mon Sep 17 00:00:00 2001 From: Pavel Makhov Date: Sat, 26 Jan 2019 22:54:49 -0500 Subject: add error handling to weather widget --- weather-widget/weather.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/weather-widget/weather.lua b/weather-widget/weather.lua index 973a776..06897b7 100644 --- a/weather-widget/weather.lua +++ b/weather-widget/weather.lua @@ -98,8 +98,15 @@ local weather_timer = gears.timer({ timeout = 60 }) local resp weather_timer:connect_signal("timeout", function () - local resp_json = http.request("https://api.openweathermap.org/data/2.5/weather?q=" .. secrets.weather_widget_city .."&appid=" .. secrets.weather_widget_api_key) - if (resp_json ~= nil) then + local resp_json, status = http.request("https://api.openweathermap.org/data/2.5/weather?q=" .. secrets.weather_widget_city .."&appid=" .. secrets.weather_widget_api_key) + if (status ~= 200) then + local err_resp = json.decode(resp_json) + naughty.notify{ + title = 'Weather Widget Error', + text = err_resp.message, + preset = naughty.config.presets.critical, + } + elseif (resp_json ~= nil) then resp = json.decode(resp_json) icon_widget.image = path_to_icons .. icon_map[resp.weather[1].icon] temp_widget:set_text(to_celcius(resp.main.temp) .. "°C") -- cgit v1.2.3