Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added bad Request #530

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Abhishekism9450 marked this conversation as resolved.
Show resolved Hide resolved
}

if c == http.StatusBadRequest {
return fmt.Errorf("bad Request")
}

buf, err := ioutil.ReadAll(r.Body)
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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))
}
Expand Down
12 changes: 6 additions & 6 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
}
}

Expand All @@ -303,16 +303,16 @@ 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)

if err == nil {
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")
}
}

Expand Down