cmd/gomobile/init: report non-200 HTTP responses

Change-Id: I415a6c4693be340ff8236d5f56c3c00fa95ce2e0
Reviewed-on: https://go-review.googlesource.com/6822
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
This commit is contained in:
Burcu Dogan 2015-03-04 14:23:54 -08:00
parent d6d776925d
commit 4940f61621
1 changed files with 12 additions and 4 deletions

View File

@ -532,16 +532,24 @@ func fetch(dst, url string) error {
if err != nil {
return err
}
_, err = io.Copy(f, resp.Body)
err2 := resp.Body.Close()
err3 := f.Close()
var err2 error
if resp.StatusCode != http.StatusOK {
err = fmt.Errorf("error fetching %v, status: %v", url, resp.Status)
} else {
_, err2 = io.Copy(f, resp.Body)
}
err3 := resp.Body.Close()
err4 := f.Close()
if err != nil {
return err
}
if err2 != nil {
return err2
}
return err3
if err3 != nil {
return err3
}
return err4
}
// copyGoroot copies GOROOT from src to dst.