feat: add error logging for HTTP requests and command processing in inventoryWebBridge
This commit is contained in:
@@ -102,6 +102,7 @@ local function httpPost(path, body)
|
||||
if ok then
|
||||
return result
|
||||
end
|
||||
print(string.format("[ERR] HTTP POST %s: %s", path, tostring(result)))
|
||||
return nil
|
||||
end
|
||||
|
||||
@@ -121,6 +122,7 @@ local function httpGet(path)
|
||||
if ok then
|
||||
return result
|
||||
end
|
||||
print(string.format("[ERR] HTTP GET %s: %s", path, tostring(result)))
|
||||
return nil
|
||||
end
|
||||
|
||||
@@ -255,13 +257,16 @@ local function modemListener()
|
||||
local resultType = message.type
|
||||
if resultType == "order_result" or resultType == "craft_result"
|
||||
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,
|
||||
commandId = message.commandId,
|
||||
success = message.success,
|
||||
message = message.message,
|
||||
error = message.error,
|
||||
})
|
||||
if not fwdOk then
|
||||
print(string.format("[ERR] Forward result %s: %s", resultType, tostring(fwdErr)))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -272,7 +277,7 @@ local function stateForwarder()
|
||||
while running do
|
||||
local ok, err = pcall(forwardState)
|
||||
if not ok then
|
||||
-- Connection error, will retry
|
||||
print(string.format("[ERR] State forward: %s", tostring(err)))
|
||||
end
|
||||
sleep(STATE_INTERVAL)
|
||||
end
|
||||
@@ -291,7 +296,10 @@ local function commandPoller()
|
||||
for _, cmd in ipairs(result.commands) do
|
||||
local cmdId = cmd.id or 0
|
||||
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
|
||||
end
|
||||
end
|
||||
@@ -302,6 +310,9 @@ local function commandPoller()
|
||||
end
|
||||
end
|
||||
end)
|
||||
if not ok then
|
||||
print(string.format("[ERR] Command poll: %s", tostring(err)))
|
||||
end
|
||||
sleep(POLL_INTERVAL)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user