commit d8871723242353c97b9b53a040ffb3bd8ccbd9cd
Author: selfhoster1312 <selfhoster1312@kl.netlib.re>
Date: Sat Nov 22 13:19:40 2025 +0000
diff --git a/bridge/helper/helper.go b/bridge/helper/helper.go
index b90c906..b361e46 100644
--- a/bridge/helper/helper.go
+++ b/bridge/helper/helper.go
@@ -26 +27 @@ package helper
import (
"bytes"
+ "errors"
"fmt"
"image/png"
"io"
@@ -206 +2112 @@ import (
"github.com/sirupsen/logrus"
)
+var errHttpGetNotOk = errors.New("HTTP server responded non-OK code")
+
+func HttpGetNotOkError(url string, code int) error {
+ return fmt.Errorf("%w: %s returned code %d", errHttpGetNotOk, url, code)
+}
+
// DownloadFile downloads the given non-authenticated URL.
func DownloadFile(url string) (*[]byte, error) {
return DownloadFileAuth(url, "")
@@ -428 +4921 @@ func DownloadFileAuth(url string, auth string) (*[]byte, error) {
if err != nil {
return nil, err
}
- defer resp.Body.Close()
- io.Copy(&buf, resp.Body)
+
+ if resp.StatusCode != http.StatusOK {
+ return nil, HttpGetNotOkError(url, resp.StatusCode)
+ }
+
+ _, err = io.Copy(&buf, resp.Body)
+ if err != nil {
+ return nil, err
+ }
+
+ err = resp.Body.Close()
+ if err != nil {
+ return nil, err
+ }
+
data := buf.Bytes()
return &data, nil
}