diff --git a/client/client.go b/client/client.go index 08837779..2decd025 100644 --- a/client/client.go +++ b/client/client.go @@ -550,7 +550,11 @@ func CheckResponse(r *http.Response) error { // Nutanix returns non-json response with code 401 when // invalid credentials are used if c == http.StatusUnauthorized { - return fmt.Errorf("invalid Nutanix Credentials") + return fmt.Errorf("invalid auth Credentials") + } + + if c == http.StatusBadRequest { + return fmt.Errorf("bad Request") } buf, err := ioutil.ReadAll(r.Body) @@ -574,7 +578,6 @@ func CheckResponse(r *http.Response) error { if err != nil { return fmt.Errorf("unmarshalling error response %s for response body %s", err, string(buf)) } - log.Print("[DEBUG] after json.Unmarshal") errRes := &ErrorResponse{} if status, ok := res["status"]; ok { @@ -590,11 +593,9 @@ func CheckResponse(r *http.Response) error { return nil } - log.Print("[DEBUG] after bunch of switch cases") if err != nil { return err } - log.Print("[DEBUG] first nil check") // karbon error check if messageInfo, ok := res["message_info"]; ok { @@ -610,7 +611,6 @@ func CheckResponse(r *http.Response) error { return nil } - log.Print("[DEBUG] after errRes.State") pretty, _ := json.MarshalIndent(errRes, "", " ") return fmt.Errorf("error: %s", string(pretty)) } diff --git a/client/client_test.go b/client/client_test.go index dc9ff73c..6c4d45fd 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -283,7 +283,7 @@ func TestGetResponse(t *testing.T) { StatusCode: http.StatusBadRequest, Body: ioutil.NopCloser(strings.NewReader( `{"api_version": "3.1", "code": 400, "kind": "error", "message_list": - [{"message": "This field may not be blank."}], "state": "ERROR"}`)), + [{"message": "bad Request"}], "state": "ERROR"}`)), } err := CheckResponse(res) @@ -292,8 +292,8 @@ func TestGetResponse(t *testing.T) { t.Fatal("Expected error response.") } - if !strings.Contains(fmt.Sprint(err), "This field may not be blank.") { - t.Errorf("error = %#v, expected %#v", err, "This field may not be blank.") + if !strings.Contains(fmt.Sprint(err), "bad Request") { + t.Errorf("error = %#v, expected %#v", err, "bad Request") } } @@ -303,7 +303,7 @@ func TestCheckResponse(t *testing.T) { StatusCode: http.StatusBadRequest, Body: ioutil.NopCloser(strings.NewReader( `{"api_version": "3.1", "code": 400, "kind": "error", "message_list": - [{"message": "This field may not be blank."}], "state": "ERROR"}`)), + [{"message": "bad Request"}], "state": "ERROR"}`)), } err := CheckResponse(res) @@ -311,8 +311,8 @@ func TestCheckResponse(t *testing.T) { t.Fatalf("Expected error response.") } - if !strings.Contains(fmt.Sprint(err), "This field may not be blank.") { - t.Errorf("error = %#v, expected %#v", err, "This field may not be blank.") + if !strings.Contains(fmt.Sprint(err), "bad Request") { + t.Errorf("error = %#v, expected %#v", err, "bad Request") } }