From 8a18810c66d9200c3c54b6f2a696f213e854f39b Mon Sep 17 00:00:00 2001 From: ppacher Date: Tue, 7 Apr 2020 10:50:56 +0200 Subject: [PATCH] Do not ingore HTTP status code when fetching files --- updater/fetch.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/updater/fetch.go b/updater/fetch.go index e7e1373..8b7853b 100644 --- a/updater/fetch.go +++ b/updater/fetch.go @@ -50,6 +50,10 @@ func (reg *ResourceRegistry) fetchFile(rv *ResourceVersion, tries int) error { } defer resp.Body.Close() + if resp.StatusCode != http.StatusOK { + return fmt.Errorf("error fetching url (%s): %s", downloadURL, resp.Status) + } + // download and write file n, err := io.Copy(atomicFile, resp.Body) if err != nil { @@ -96,6 +100,10 @@ func (reg *ResourceRegistry) fetchData(downloadPath string, tries int) ([]byte, } defer resp.Body.Close() + if resp.StatusCode != http.StatusOK { + return nil, fmt.Errorf("error fetching url (%s): %s", downloadURL, resp.Status) + } + // download and write file buf := bytes.NewBuffer(make([]byte, 0, resp.ContentLength)) n, err := io.Copy(buf, resp.Body)