Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion ovh/ovh.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,10 @@ func (c *Client) getResponse(response *http.Response, resType interface{}) error
if response.StatusCode < http.StatusOK || response.StatusCode >= http.StatusMultipleChoices {
apiError := &APIError{Code: response.StatusCode}
if err = json.Unmarshal(body, apiError); err != nil {
return err
apiError.Message = string(body)
}
apiError.QueryID = response.Header.Get("X-Ovh-QueryID")

return apiError
}

Expand Down
26 changes: 25 additions & 1 deletion ovh/ovh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func initMockServer(InputRequest **http.Request, status int, responseBody string
// Respond
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
fmt.Fprintln(w, responseBody)
fmt.Fprint(w, responseBody)
}))

// Create client
Expand Down Expand Up @@ -131,6 +131,30 @@ func TestPing(t *testing.T) {
}
}

func TestError500HTML(t *testing.T) {
// Init test
var InputRequest *http.Request
errHTML := `<html><body><p>test</p></body></html>`
ts, client := initMockServer(&InputRequest, http.StatusServiceUnavailable, errHTML, nil)
defer ts.Close()

// Test
var res struct{}
err := client.CallAPI("GET", "/test", nil, &res, false)

// Validate
if err == nil {
t.Fatal("Expected error")
}
apiError := &APIError{
Code: http.StatusServiceUnavailable,
Message: errHTML,
}
if err.Error() != apiError.Error() {
t.Fatalf("Missmatch errors : \n%s\n%s", err, apiError)
}
}

func TestPingUnreachable(t *testing.T) {
// Init test
var InputRequest *http.Request
Expand Down