From 17c1ed11117d5a7dc9ddb1936264478d9d9dcbbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sun, 14 Feb 2016 23:30:39 +0000 Subject: [PATCH] cmd/fdroidcl: treat HTTP error codes Fixes #3. --- cmd/fdroidcl/update.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cmd/fdroidcl/update.go b/cmd/fdroidcl/update.go index d91d0d7..b46993d 100644 --- a/cmd/fdroidcl/update.go +++ b/cmd/fdroidcl/update.go @@ -6,7 +6,6 @@ package main import ( "bytes" "crypto/sha256" - "errors" "fmt" "io" "io/ioutil" @@ -93,6 +92,10 @@ func downloadEtag(url, path string, sum []byte) error { return err } defer resp.Body.Close() + if resp.StatusCode >= 400 { + return fmt.Errorf("download failed: %d %s", + resp.StatusCode, http.StatusText(resp.StatusCode)) + } if resp.StatusCode == http.StatusNotModified { fmt.Printf("not modified") return nil @@ -114,7 +117,7 @@ func downloadEtag(url, path string, sum []byte) error { } got := sha256.Sum256(data) if !bytes.Equal(sum, got[:]) { - return errors.New("sha256 mismatch") + return fmt.Errorf("sha256 mismatch") } if _, err := f.Write(data); err != nil { return err