return more specific error when response from module proxy is not 200

This commit is contained in:
Shawn Smith
2021-11-15 18:56:50 +09:00
parent 6c35f4e2e8
commit af83df5612

View File

@@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"os/exec"
@@ -22,13 +23,19 @@ type moduleVersion struct {
// ProxyDownload downloads a package from proxy.golang.org
func ProxyDownload(path string) (string, error) {
resp, err := http.Get(fmt.Sprintf(proxyLatestURL, path))
u := fmt.Sprintf(proxyLatestURL, path)
resp, err := http.Get(u)
if err != nil {
return "", err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
b, _ := ioutil.ReadAll(resp.Body)
return "", fmt.Errorf("could not get latest module version from %s: %s", u, string(b))
}
var mv moduleVersion
err = json.NewDecoder(resp.Body).Decode(&mv)