mirror of
https://github.com/gojp/goreportcard.git
synced 2026-01-28 22:39:05 +08:00
return more specific error when response from module proxy is not 200
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user