Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: Check status 200 and other errors in helper.DownloadFile
  • Loading branch information
selfhoster1312 committed Nov 22, 2025
commit e245775af08c568345b7f1798964eafcaeeb028f
24 changes: 22 additions & 2 deletions bridge/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package helper

import (
"bytes"
"errors"
"fmt"
"image/png"
"io"
Expand All @@ -20,6 +21,12 @@ 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, "")
Expand All @@ -42,8 +49,21 @@ 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
}
Expand Down