Merge pull request #3 from fgiudici/status_in_dial_error

Include more info in the error msg on Dial() error
This commit is contained in:
Francesco Giudici 2022-08-11 14:12:55 +02:00 committed by GitHub
commit baef878366
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

12
get.go
View File

@ -68,10 +68,14 @@ func Get(url string, opts ...Option) ([]byte, error) {
logrus.Infof("Using TPMHash %s to dial %s", hash, wsURL)
conn, resp, err := dialer.Dial(wsURL, header)
if err != nil {
if resp != nil && resp.StatusCode == http.StatusUnauthorized {
data, err := ioutil.ReadAll(resp.Body)
if err == nil {
return nil, errors.New(string(data))
if resp != nil {
if resp.StatusCode == http.StatusUnauthorized {
data, err := ioutil.ReadAll(resp.Body)
if err == nil {
return nil, errors.New(string(data))
}
} else {
return nil, fmt.Errorf("%w (Status: %s)", err, resp.Status)
}
}
return nil, err