diff options
author | Pavel Makhov <pmakhov@touchtunes.com> | 2019-01-26 22:54:49 -0500 |
---|---|---|
committer | Pavel Makhov <pmakhov@touchtunes.com> | 2019-01-26 22:54:49 -0500 |
commit | ee396d7c5b45d0dea4160f5cef0f0bc81980dd1f (patch) | |
tree | 412baf4c86af89ffbd783bda959e046482b8a32d /weather-widget | |
parent | 1d08a478fd02c1c8405754ebc0b9d5a146b865f3 (diff) |
add error handling to weather widget
Diffstat (limited to 'weather-widget')
-rw-r--r-- | weather-widget/weather.lua | 11 |
1 files 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") |