fuzzyworld

find-stone-beer / commit

Added a status code check to the url getter, expecting 200 at all times.

4cc684dc245079ecdf782185b378df1502ddd6c2 · Pavel Safronov · 2023-09-14 11:14:29 -0700 · parents 6cc7663b4813

Added a status code check to the url getter, expecting 200 at all times.
 main.go   | 4 ++++
 seller.go | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/main.go b/main.go
index 5a202fe..ab0ff3f 100644
--- a/main.go
+++ b/main.go
@@ -199,6 +199,10 @@ func getCachedUrlFunc(url string, id string, cacheFileTimeFormat string, bytePro
 			return nil, err
 		}
 
+		if resp.StatusCode != 200 {
+			return nil, fmt.Errorf("tried reaching %s, got status code %d and body %s", url, resp.StatusCode, string(body))
+		}
+
 		body, err = byteProcessor(body)
 		if err != nil {
 			return nil, err
diff --git a/seller.go b/seller.go
index bb64dd2..28d273e 100644
--- a/seller.go
+++ b/seller.go
@@ -96,7 +96,7 @@ func GetSellers(coords geodist.Coord) ([]Seller, error) {
 	var sellers []Seller
 	err = json.Unmarshal(bytes, &sellers)
 	if err != nil {
-		return nil, err
+		return nil, fmt.Errorf("error unmarshalling json '%s': %w", string(bytes), err)
 	}
 	return sellers, nil
 }