Fix pcall return value handling in HTTP client
pcall wraps socket.http.request returns as: true, 1, status_code, headers, status_line The old code captured '1' as the status code instead of the actual HTTP status. Added '_' to skip the first return.
This commit is contained in:
+5
-5
@@ -59,23 +59,23 @@ function BookhoardAPI:_request(method, path, body, timeouts)
|
||||
|
||||
socketutil:set_timeout(timeouts[1], timeouts[2])
|
||||
|
||||
local ok, code
|
||||
local ok, _, code
|
||||
if url:match("^https://") then
|
||||
if ssl_ok then
|
||||
ok, code = pcall(ssl_https.request, request)
|
||||
ok, _, code = pcall(ssl_https.request, request)
|
||||
else
|
||||
socketutil:reset_timeout()
|
||||
return false, { error = "HTTPS not supported on this device" }
|
||||
end
|
||||
else
|
||||
ok, code = pcall(http.request, request)
|
||||
ok, _, code = pcall(http.request, request)
|
||||
end
|
||||
|
||||
socketutil:reset_timeout()
|
||||
|
||||
if not ok then
|
||||
logger.warn("BookhoardAPI: request failed:", code)
|
||||
return false, { error = tostring(code) }
|
||||
logger.warn("BookhoardAPI: request failed:", _)
|
||||
return false, { error = tostring(_) }
|
||||
end
|
||||
|
||||
local response_body = table.concat(sink)
|
||||
|
||||
Reference in New Issue
Block a user