uptime-widget: add error handling

This commit is contained in:
Evgeny
2022-06-04 09:05:16 +03:00
parent 82a4075f41
commit 7ed2f9c0e1

View File

@@ -3,7 +3,7 @@
-- data_source = "uptimerobot.com" -- data_source = "uptimerobot.com"
-- type = "widget" -- type = "widget"
-- author = "Evgeny Zobnin (zobnin@gmail.com) -- author = "Evgeny Zobnin (zobnin@gmail.com)
-- version = "1.0" -- version = "1.1"
-- arguments_help = "Enter your API key" -- arguments_help = "Enter your API key"
local json = require "json" local json = require "json"
@@ -34,7 +34,12 @@ function on_click()
end end
end end
function on_network_result(result) function on_network_result(result, code)
if (code >= 400) then
ui:show_text("Error: "..code)
return
end
local parsed = json.decode(result) local parsed = json.decode(result)
if (parsed.stat ~= "ok") then if (parsed.stat ~= "ok") then