Do not ingore HTTP status code when fetching files

This commit is contained in:
ppacher 2020-04-07 10:50:56 +02:00
parent 3d9920935e
commit 8a18810c66

View file

@ -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)