diff --git a/src/runtime/pkg/utils/shimclient/shim_management_client.go b/src/runtime/pkg/utils/shimclient/shim_management_client.go index 81c0d70dec..3f9e686507 100644 --- a/src/runtime/pkg/utils/shimclient/shim_management_client.go +++ b/src/runtime/pkg/utils/shimclient/shim_management_client.go @@ -9,6 +9,7 @@ import ( "bytes" "fmt" "io" + "io/ioutil" "net" "net/http" "time" @@ -79,12 +80,22 @@ func DoPut(sandboxID string, timeoutInSeconds time.Duration, urlPath, contentTyp req.Header.Set("Content-Type", contentType) resp, err := client.Do(req) + if err != nil { + return err + } + defer func() { if resp != nil { resp.Body.Close() } }() - return err + + if resp.StatusCode != http.StatusOK { + data, _ := ioutil.ReadAll(resp.Body) + return fmt.Errorf("error sending put: url: %s, status code: %d, response data: %s", urlPath, resp.StatusCode, string(data)) + } + + return nil } // DoPost will make a POST request to the shim endpoint that handles the given sandbox ID @@ -95,10 +106,20 @@ func DoPost(sandboxID string, timeoutInSeconds time.Duration, urlPath, contentTy } resp, err := client.Post(fmt.Sprintf("http://shim%s", urlPath), contentType, bytes.NewBuffer(payload)) + if err != nil { + return err + } + defer func() { if resp != nil { resp.Body.Close() } }() - return err + + if resp.StatusCode != http.StatusOK { + data, _ := ioutil.ReadAll(resp.Body) + return fmt.Errorf("error sending post: url: %s, status code: %d, response data: %s", urlPath, resp.StatusCode, string(data)) + } + + return nil }