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])
|
socketutil:set_timeout(timeouts[1], timeouts[2])
|
||||||
|
|
||||||
local ok, code
|
local ok, _, code
|
||||||
if url:match("^https://") then
|
if url:match("^https://") then
|
||||||
if ssl_ok then
|
if ssl_ok then
|
||||||
ok, code = pcall(ssl_https.request, request)
|
ok, _, code = pcall(ssl_https.request, request)
|
||||||
else
|
else
|
||||||
socketutil:reset_timeout()
|
socketutil:reset_timeout()
|
||||||
return false, { error = "HTTPS not supported on this device" }
|
return false, { error = "HTTPS not supported on this device" }
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
ok, code = pcall(http.request, request)
|
ok, _, code = pcall(http.request, request)
|
||||||
end
|
end
|
||||||
|
|
||||||
socketutil:reset_timeout()
|
socketutil:reset_timeout()
|
||||||
|
|
||||||
if not ok then
|
if not ok then
|
||||||
logger.warn("BookhoardAPI: request failed:", code)
|
logger.warn("BookhoardAPI: request failed:", _)
|
||||||
return false, { error = tostring(code) }
|
return false, { error = tostring(_) }
|
||||||
end
|
end
|
||||||
|
|
||||||
local response_body = table.concat(sink)
|
local response_body = table.concat(sink)
|
||||||
|
|||||||
Reference in New Issue
Block a user