diff --git a/CHANGELOG.md b/CHANGELOG.md index 532395e4c..c30467f49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ IMPROVEMENTS: BUG FIXES: +* core: Non-200 response codes on downloads now show proper errors. + [GH-141] * vagrant: The `BuildName` template propery works properly in the output path. * vagrant: Properly configure the provider-specific post-processors so diff --git a/builder/common/download.go b/builder/common/download.go index ff59faea4..d5d97d1c0 100644 --- a/builder/common/download.go +++ b/builder/common/download.go @@ -107,6 +107,9 @@ func (d *DownloadClient) Get() (string, error) { log.Printf("Downloading: %s", url.String()) err = d.downloader.Download(f, url) + if err != nil { + return "", err + } } if d.config.Hash != nil { @@ -160,11 +163,22 @@ func (*HTTPDownloader) Cancel() { } func (d *HTTPDownloader) Download(dst io.Writer, src *url.URL) error { + log.Printf("Starting download: %s", src.String()) resp, err := http.Get(src.String()) if err != nil { return err } + if resp.StatusCode != 200 { + log.Printf( + "Non-200 status code: %d. Getting error body.", resp.StatusCode) + + errorBody := new(bytes.Buffer) + io.Copy(errorBody, resp.Body) + return fmt.Errorf("HTTP error '%d'! Remote side responded:\n%s", + resp.StatusCode, errorBody.String()) + } + d.progress = 0 d.total = uint(resp.ContentLength)