Return early if response status is not "OK"
@@ -61,6 +61,10 @@ func downloadFile(remoteURL, dir string) (string, error) {
}
defer resp.Body.Close()
+ if resp.StatusCode != 200 {
+ return "", errors.Errorf("unexpected status code: %d", resp.StatusCode)
+ }
+
fmt.Printf("Downloading file %s\n", remoteURL)
bar := progressbar.DefaultBytes(
resp.ContentLength,
@@ -72,10 +76,6 @@ func downloadFile(remoteURL, dir string) (string, error) {
return "", errors.Wrap(err, "downloading the remote file")
}
- if resp.StatusCode != 200 {
- return "", errors.Errorf("unexpected status code: %d", resp.StatusCode)
- }
-
return tmpFile.Name(), nil
}
