From: Petr Špaček Date: Mon, 30 Dec 2019 10:43:03 +0000 (+0100) Subject: utils: log errors from HTTPS client library X-Git-Tag: v5.0.0~13^2~4 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=42fb1db18a785a0a57db0d3b6dc5e55c66791352;p=thirdparty%2Fknot-resolver.git utils: log errors from HTTPS client library Previous code inconsistently thrown some errors and returned as string other ones, so we now return all errors as strings in classic Lua-style. --- diff --git a/daemon/lua/kluautil.lua b/daemon/lua/kluautil.lua index 825cbf4e8..773738cf7 100644 --- a/daemon/lua/kluautil.lua +++ b/daemon/lua/kluautil.lua @@ -29,15 +29,19 @@ function kluautil.kr_https_fetch(url, ca_file, file) req.ctx:setVerify(openssl_ctx.VERIFY_PEER) req.tls = true - local headers, stream = req:go() - assert(headers, 'HTTP client library error') + local headers, stream, errmsg = req:go() + if not headers then + errmsg = errmsg or 'unknown error' + return nil, 'HTTP client library error: ' .. errmsg + end if headers:get(':status') ~= "200" then - return nil, headers:get(':status') + return nil, 'HTTP status != 200, got ' .. headers:get(':status') end - local err, errmsg = stream:save_body_to_file(file) + local err + err, errmsg = stream:save_body_to_file(file) if err == nil then - return err, errmsg + return nil, errmsg end file:seek ("set", 0)