From a11774d81d4cc62da02d6265848bd7fc2d15c011 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Mon, 9 Jan 2023 10:53:21 +0530 Subject: [PATCH 1/3] added bad Request --- client/client.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/client/client.go b/client/client.go index 088377798..299108f0c 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 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)) } From 42c37d43bbe37064bdef88d9d80b1d7c44e78755 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Thu, 12 Jan 2023 12:00:32 +0530 Subject: [PATCH 2/3] modified tcs for bad request --- client/client_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/client/client_test.go b/client/client_test.go index dc9ff73c7..6c4d45fd8 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") } } From 074eeea51ab5ef97f3721d3db9e3072a7d70a173 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Fri, 13 Jan 2023 12:18:38 +0530 Subject: [PATCH 3/3] updated error msg --- client/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/client.go b/client/client.go index 299108f0c..2decd025a 100644 --- a/client/client.go +++ b/client/client.go @@ -550,7 +550,7 @@ 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 Credentials") + return fmt.Errorf("invalid auth Credentials") } if c == http.StatusBadRequest {