builder/common: Error on non-200 download responses [GH-141]

This commit is contained in:
Mitchell Hashimoto 2013-07-07 12:16:31 -07:00
parent 308205cc6f
commit abc2bc60ab
2 changed files with 16 additions and 0 deletions

View File

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

View File

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