Tidying error handling and adding some fluff.

This commit is contained in:
Fred Boniface
2024-04-28 10:25:41 +01:00
parent 01da611d26
commit b93d36dacd
6 changed files with 23 additions and 6 deletions

View File

@@ -2,6 +2,7 @@ package nrod
import (
"compress/gzip"
"errors"
"fmt"
"io"
"net/http"
@@ -22,7 +23,6 @@ func NrodStream(url string, cfg *helpers.Configuration) (io.ReadCloser, error) {
req, err := http.NewRequest("GET", url, nil)
if err != nil {
log.Error("Error creating HTTP Request", zap.Error(err))
return nil, err
}
@@ -34,9 +34,13 @@ func NrodStream(url string, cfg *helpers.Configuration) (io.ReadCloser, error) {
return nil, err
}
if resp == nil {
err = errors.New("http response error - response = nil")
return nil, err
}
if resp.StatusCode != http.StatusOK {
err := fmt.Errorf("unexpected status code: %d", resp.StatusCode)
log.Error("Non-successful status code", zap.Error(err))
return nil, err
}