Merge pull request #7630 from mikesplain/automated-cherry-pick-of-#7611-origin-release-1.14

Automated cherry pick of #7611: Check the HTTP response code when downloading URLs
This commit is contained in:
Kubernetes Prow Robot 2019-09-18 13:55:00 -07:00 committed by GitHub
commit f3366320d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 0 deletions

View File

@ -80,6 +80,9 @@ func downloadURLAlways(url string, destPath string, dirMode os.FileMode) error {
if err != nil {
return fmt.Errorf("error doing HTTP fetch of %q: %v", url, err)
}
if response.StatusCode >= 400 {
return fmt.Errorf("error response from %q: HTTP %v", url, response.StatusCode)
}
defer response.Body.Close()
_, err = io.Copy(output, response.Body)