From 42fb1db18a785a0a57db0d3b6dc5e55c66791352 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Petr=20=C5=A0pa=C4=8Dek?= Date: Mon, 30 Dec 2019 11:43:03 +0100 Subject: [PATCH] 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. --- daemon/lua/kluautil.lua | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) 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) -- 2.47.3