From 30058b554bea3ca94a0298e8850ab9a8efe3c65c Mon Sep 17 00:00:00 2001 From: Francesco Giudici Date: Wed, 10 Aug 2022 09:40:14 +0200 Subject: [PATCH] Include more info in the error msg on Dial() error Include the HTTP Status CODE: it could help in diagnosing the connection failure. Signed-off-by: Francesco Giudici --- get.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/get.go b/get.go index 35073a0..b8a9f21 100644 --- a/get.go +++ b/get.go @@ -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