From 4940f616214fa25e0de68074daef68a3543defb5 Mon Sep 17 00:00:00 2001 From: Burcu Dogan Date: Wed, 4 Mar 2015 14:23:54 -0800 Subject: [PATCH] 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 --- cmd/gomobile/init.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/cmd/gomobile/init.go b/cmd/gomobile/init.go index 2906dda..0bbaa77 100644 --- a/cmd/gomobile/init.go +++ b/cmd/gomobile/init.go @@ -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.