summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAurélien LAJOIE <orel@melix.net>2019-09-18 01:27:22 +0200
committerAurélien LAJOIE <orel@melix.net>2019-09-18 01:27:22 +0200
commit59ce0053ac15f862e9571034cac28fd1063bef0e (patch)
tree531a75082b9a6e61c5b2b905e6a26c0630bb1f38
parent2f20cc54c792c38f52072e2f6afb92eb6e1421ec (diff)
Catch error is the answer is not a valid json string
This was triggered by a public wifi pushing an html file to all request
-rw-r--r--weather-widget/weather.lua22
1 files changed, 16 insertions, 6 deletions
diff --git a/weather-widget/weather.lua b/weather-widget/weather.lua
index b0aa070..09eeeec 100644
--- a/weather-widget/weather.lua
+++ b/weather-widget/weather.lua
@@ -142,6 +142,15 @@ local function worker(args)
return s
end
+ local function error_display(resp_json)
+ local err_resp = json.decode(resp_json)
+ naughty.notify{
+ title = 'Weather Widget Error',
+ text = err_resp.message,
+ preset = naughty.config.presets.critical,
+ }
+ end
+
weather_timer:connect_signal("timeout", function ()
local resp_json = {}
local res, status = http.request{
@@ -164,12 +173,13 @@ local function worker(args)
end
if (status ~= 200 and resp_json ~= nil and resp_json ~= '') then
- local err_resp = json.decode(resp_json)
- naughty.notify{
- title = 'Weather Widget Error',
- text = err_resp.message,
- preset = naughty.config.presets.critical,
- }
+ if (not pcall(error_display, resp_json)) then
+ naughty.notify{
+ title = 'Weather Widget Error',
+ text = 'Cannot parse answer',
+ preset = naughty.config.presets.critical,
+ }
+ end
elseif (resp_json ~= nil and resp_json ~= '') then
resp = json.decode(resp_json)
icon_widget.image = path_to_icons .. icon_map[resp.weather[1].icon]