diff --git a/frontend/ui/translator.lua b/frontend/ui/translator.lua index 76cf4dd43..b29be84b0 100644 --- a/frontend/ui/translator.lua +++ b/frontend/ui/translator.lua @@ -62,8 +62,13 @@ function Translator:loadPage(target_lang, source_lang, text) error("Network is unreachable") end + if status ~= "HTTP/1.1 200 OK" then + DEBUG("HTTP status not okay:", status) + return + end + local content = table.concat(sink) - if content ~= "" then + if content ~= "" and string.sub(content, 1,1) == "{" then local ok, result = pcall(JSON.decode, content) if ok and result then --DEBUG("translate result", result) @@ -71,6 +76,8 @@ function Translator:loadPage(target_lang, source_lang, text) else DEBUG("error:", result) end + else + DEBUG("not JSON:", content) end end diff --git a/frontend/ui/wikipedia.lua b/frontend/ui/wikipedia.lua index 77c2120c2..c2e9a896f 100644 --- a/frontend/ui/wikipedia.lua +++ b/frontend/ui/wikipedia.lua @@ -7,7 +7,7 @@ local DEBUG = require("dbg") --]] local Wikipedia = { - wiki_server = "http://%s.wikipedia.org", + wiki_server = "https://%s.wikipedia.org", wiki_path = "/w/api.php", wiki_params = { action = "query", @@ -59,8 +59,13 @@ function Wikipedia:loadPage(text, lang, intro, plain) error("Network is unreachable") end + if status ~= "HTTP/1.1 200 OK" then + DEBUG("HTTP status not okay:", status) + return + end + local content = table.concat(sink) - if content ~= "" then + if content ~= "" and string.sub(content, 1,1) == "{" then local ok, result = pcall(JSON.decode, content) if ok and result then DEBUG("wiki result", result) @@ -68,6 +73,8 @@ function Wikipedia:loadPage(text, lang, intro, plain) else DEBUG("error:", result) end + else + DEBUG("not JSON:", content) end end