Berry Matter improve async HTTP error handling (#24756)

This commit is contained in:
s-hadinger
2026-05-16 23:40:37 +02:00
committed by GitHub
parent 5009bea30b
commit cfe25959cd
3 changed files with 9 additions and 11 deletions

View File

@@ -306,7 +306,7 @@ class Matter_HTTP_remote : Matter_HTTP_async
var ret = super(self).begin_sync(cmd_url, timeout)
var payload_short = (ret) ? ret : 'nil'
if size(payload_short) > 30 payload_short = payload_short[0..29] + '...' end
log(format("MTR: HTTP sync-resp in %i ms from %s: [%i] '%s'", tasmota.millis() - self.time_start, self.addr, size(self.payload), payload_short), 3)
log(f"MTR: HTTP {'sync'}-resp in {tasmota.millis() - self.time_start} ms from {self.addr}: [{size(self.payload)}] '{payload_short}'", 3)
return ret
end
@@ -314,17 +314,17 @@ class Matter_HTTP_remote : Matter_HTTP_async
if self.current_cmd == nil return end # do nothing if sync request
var payload_short = (self.payload != nil) ? self.payload : 'nil'
if size(payload_short) > 30 payload_short = payload_short[0..29] + '...' end
log(format("MTR: HTTP async-resp in %i ms from %s: [%i] '%s'", tasmota.millis() - self.time_start, self.addr, size(self.payload), payload_short), 3)
log(f"MTR: HTTP {'async'}-resp in {tasmota.millis() - self.time_start} ms from {self.addr}: [{size(self.payload)}] '{payload_short}'", 3)
self.dispatch_cb(self.http_status, self.payload)
end
def event_http_failed()
if self.current_cmd == nil return end # do nothing if sync request
log("MTR: HTTP failed", 3)
log(f"MTR: HTTP failed in={tasmota.millis() - self.time_start} ms from {self.addr}", 3)
self.dispatch_cb(self.http_status, nil)
end
def event_http_timeout()
if self.current_cmd == nil return end # do nothing if sync request
log(format("MTR: HTTP timeout http_status=%i phase=%i tcp_status=%i size_payload=%i", self.http_status, self.phase, self.status, size(self.payload)), 3)
log(f"MTR: HTTP timeout in={tasmota.millis() - self.time_start} ms from {self.addr}", 3)
self.dispatch_cb(self.http_status, nil)
end

View File

@@ -147,17 +147,15 @@ class Matter_TCP_async
self.event_refused()
self.close()
return
elif (tasmota.millis() - self.time_start) > self.timeout
# connection timeout
self.status = -3
self.tcp_connected = false # force to false
self.event_timeout()
end
# if still not connected, fall through to the timeout check below
end
if (tasmota.millis() - self.time_start) > self.timeout
# connection timeout (either while connecting or after established)
self.close()
self.status = -3
self.tcp_connected = false # force to false
self.event_timeout()
return
end

View File

@@ -151,14 +151,14 @@ public:
res = getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &sockerr, &len);
if (res < 0) {
AddLog(LOG_LEVEL_DEBUG, "BRY: getsockopt on fd %d, errno: %d, \"%s\"", sockfd, errno, strerror(errno));
AddLog(LOG_LEVEL_DEBUG_MORE, "BRY: getsockopt on fd %d, errno: %d, \"%s\"", sockfd, errno, strerror(errno));
stop();
state = AsyncTCPState::REFUSED;
return;
}
if (sockerr != 0) {
AddLog(LOG_LEVEL_DEBUG, "BRY: socket error on fd %d, errno: %d, \"%s\"", sockfd, sockerr, strerror(sockerr));
AddLog(LOG_LEVEL_DEBUG_MORE, "BRY: socket error on fd %d, errno: %d, \"%s\"", sockfd, sockerr, strerror(sockerr));
stop();
state = AsyncTCPState::REFUSED;
return;