From ad30190c7742cf4b76b96a8505e404f11ac86d8b Mon Sep 17 00:00:00 2001 From: Prateek Pandey Date: Fri, 10 Aug 2018 14:07:23 +0530 Subject: [PATCH] Read http response body in case of volume creation failed (#54) This change required to get the actual error from maya-apiserver in case of volume provisioning failed. Signed-off-by: prateekpandey14 --- openebs/pkg/volume/v1alpha1/volume.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/openebs/pkg/volume/v1alpha1/volume.go b/openebs/pkg/volume/v1alpha1/volume.go index 9273bc306d9..bca6d75bd32 100644 --- a/openebs/pkg/volume/v1alpha1/volume.go +++ b/openebs/pkg/volume/v1alpha1/volume.go @@ -20,6 +20,7 @@ import ( "bytes" "encoding/json" "errors" + "fmt" "io/ioutil" "net/http" "os" @@ -117,16 +118,16 @@ func (v CASVolume) CreateVolume(vol v1alpha1.CASVolume) error { } defer resp.Body.Close() - code := resp.StatusCode - if code != http.StatusOK { - return errors.New(http.StatusText(code)) - } - data, err := ioutil.ReadAll(resp.Body) if err != nil { glog.Errorf("Unable to read response from maya-apiserver %v", err) return err } + code := resp.StatusCode + if code != http.StatusOK { + glog.Errorf("%s: failed to create volume '%s': response: %+v", http.StatusText(code), vol.Name, data) + return fmt.Errorf("%s: failed to create volume '%s': response: %+v", http.StatusText(code), vol.Name, data) + } glog.Infof("volume Successfully Created:\n%#v", string(data)) return nil @@ -201,7 +202,7 @@ func (v CASVolume) DeleteVolume(vname string, namespace string) error { code := resp.StatusCode if code != http.StatusOK { - return errors.New(http.StatusText(code)) + return fmt.Errorf("failed to delete volume %s:%s", vname, http.StatusText(code)) } glog.Info("volume Deleted Successfully initiated") return nil