feat: add error logging for HTTP requests and command processing in inventoryWebBridge

This commit is contained in:
MayaTheShy
2026-03-25 22:42:52 -04:00
parent 66ac81de65
commit 4cf1e550b7

View File

@@ -102,6 +102,7 @@ local function httpPost(path, body)
if ok then if ok then
return result return result
end end
print(string.format("[ERR] HTTP POST %s: %s", path, tostring(result)))
return nil return nil
end end
@@ -121,6 +122,7 @@ local function httpGet(path)
if ok then if ok then
return result return result
end end
print(string.format("[ERR] HTTP GET %s: %s", path, tostring(result)))
return nil return nil
end end
@@ -255,13 +257,16 @@ local function modemListener()
local resultType = message.type local resultType = message.type
if resultType == "order_result" or resultType == "craft_result" if resultType == "order_result" or resultType == "craft_result"
or resultType == "recursive_craft_result" or resultType == "find_item_result" then or resultType == "recursive_craft_result" or resultType == "find_item_result" then
pcall(httpPost, "/api/bridge/result", { local fwdOk, fwdErr = pcall(httpPost, "/api/bridge/result", {
action = resultType, action = resultType,
commandId = message.commandId, commandId = message.commandId,
success = message.success, success = message.success,
message = message.message, message = message.message,
error = message.error, error = message.error,
}) })
if not fwdOk then
print(string.format("[ERR] Forward result %s: %s", resultType, tostring(fwdErr)))
end
end end
end end
end end
@@ -272,7 +277,7 @@ local function stateForwarder()
while running do while running do
local ok, err = pcall(forwardState) local ok, err = pcall(forwardState)
if not ok then if not ok then
-- Connection error, will retry print(string.format("[ERR] State forward: %s", tostring(err)))
end end
sleep(STATE_INTERVAL) sleep(STATE_INTERVAL)
end end
@@ -291,7 +296,10 @@ local function commandPoller()
for _, cmd in ipairs(result.commands) do for _, cmd in ipairs(result.commands) do
local cmdId = cmd.id or 0 local cmdId = cmd.id or 0
if cmdId > lastProcessedId then if cmdId > lastProcessedId then
pcall(processCommand, cmd) local cmdOk, cmdErr = pcall(processCommand, cmd)
if not cmdOk then
print(string.format("[ERR] Process cmd %s: %s", tostring(cmd.action), tostring(cmdErr)))
end
if cmdId > maxId then maxId = cmdId end if cmdId > maxId then maxId = cmdId end
end end
end end
@@ -302,6 +310,9 @@ local function commandPoller()
end end
end end
end) end)
if not ok then
print(string.format("[ERR] Command poll: %s", tostring(err)))
end
sleep(POLL_INTERVAL) sleep(POLL_INTERVAL)
end end
end end