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
This commit is contained in:
parent
2f20cc54c7
commit
59ce0053ac
|
@ -142,6 +142,15 @@ local function worker(args)
|
||||||
return s
|
return s
|
||||||
end
|
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 ()
|
weather_timer:connect_signal("timeout", function ()
|
||||||
local resp_json = {}
|
local resp_json = {}
|
||||||
local res, status = http.request{
|
local res, status = http.request{
|
||||||
|
@ -164,12 +173,13 @@ local function worker(args)
|
||||||
end
|
end
|
||||||
|
|
||||||
if (status ~= 200 and resp_json ~= nil and resp_json ~= '') then
|
if (status ~= 200 and resp_json ~= nil and resp_json ~= '') then
|
||||||
local err_resp = json.decode(resp_json)
|
if (not pcall(error_display, resp_json)) then
|
||||||
naughty.notify{
|
naughty.notify{
|
||||||
title = 'Weather Widget Error',
|
title = 'Weather Widget Error',
|
||||||
text = err_resp.message,
|
text = 'Cannot parse answer',
|
||||||
preset = naughty.config.presets.critical,
|
preset = naughty.config.presets.critical,
|
||||||
}
|
}
|
||||||
|
end
|
||||||
elseif (resp_json ~= nil and resp_json ~= '') then
|
elseif (resp_json ~= nil and resp_json ~= '') then
|
||||||
resp = json.decode(resp_json)
|
resp = json.decode(resp_json)
|
||||||
icon_widget.image = path_to_icons .. icon_map[resp.weather[1].icon]
|
icon_widget.image = path_to_icons .. icon_map[resp.weather[1].icon]
|
||||||
|
|
Loading…
Reference in New Issue