Ensure consistent error handling and improve resource cleanup across widgets and APIs.

This commit is contained in:
2026-01-01 12:10:33 +01:00
parent af5a39ef75
commit 2a66278cae
9 changed files with 90 additions and 48 deletions

View File

@@ -59,7 +59,12 @@ func (ph *PiHConnector) do(method string, endpoint string, body io.Reader) []byt
if err != nil {
return make([]byte, 0)
}
defer resp.Body.Close()
defer func(Body io.ReadCloser) {
err := Body.Close()
if err != nil {
return
}
}(resp.Body)
respBody, err := io.ReadAll(resp.Body)
if err != nil {
@@ -90,7 +95,12 @@ func Connect() PiHConnector {
if err != nil {
panic(err)
}
defer resp.Body.Close()
defer func(Body io.ReadCloser) {
err := Body.Close()
if err != nil {
return
}
}(resp.Body)
respBody, err := io.ReadAll(resp.Body)
if err != nil {