From 01ac73b28c83784b97ea1d0dcc267c7062e70a59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E5=86=9B10092085?= Date: Fri, 29 Jul 2022 11:17:05 +0800 Subject: [PATCH] fix error log of crio client --- container/crio/client.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/container/crio/client.go b/container/crio/client.go index e0d63333c3..ca65ba1ad4 100644 --- a/container/crio/client.go +++ b/container/crio/client.go @@ -18,6 +18,7 @@ import ( "context" "encoding/json" "fmt" + "io/ioutil" "net" "net/http" "sync" @@ -141,7 +142,11 @@ func (c *crioClientImpl) ContainerInfo(id string) (*ContainerInfo, error) { // golang's http.Do doesn't return an error if non 200 response code is returned // handle this case here, rather than failing to decode the body if resp.StatusCode != http.StatusOK { - return nil, fmt.Errorf("Error finding container %s: Status %d returned error %s", id, resp.StatusCode, resp.Body) + respBody, err := ioutil.ReadAll(resp.Body) + if err != nil { + return nil, fmt.Errorf("Error finding container %s: Status %d", id, resp.StatusCode) + } + return nil, fmt.Errorf("Error finding container %s: Status %d returned error %s", id, resp.StatusCode, string(respBody)) } if err := json.NewDecoder(resp.Body).Decode(&cInfo); err != nil {