]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
utils: log errors from HTTPS client library
authorPetr Špaček <petr.spacek@nic.cz>
Mon, 30 Dec 2019 10:43:03 +0000 (11:43 +0100)
committerLukáš Ježek <lukas.jezek@nic.cz>
Tue, 7 Jan 2020 10:02:28 +0000 (11:02 +0100)
Previous code inconsistently thrown some errors and returned as string
other ones, so we now return all errors as strings in classic Lua-style.

daemon/lua/kluautil.lua

index 825cbf4e805d0b7b91bb0d2d900eba2876704e1b..773738cf7027d8d9bc4a622615785630882ab585 100644 (file)
@@ -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)