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
2 changes: 2 additions & 0 deletions ovh/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ type APIError struct {
Message string
// HTTP code.
Code int
// ID of the request
QueryID string
}

func (err *APIError) Error() string {
Expand Down
2 changes: 1 addition & 1 deletion ovh/ovh.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (c *Client) getResponse(response *http.Response, resType interface{}) error
if err = json.Unmarshal(body, apiError); err != nil {
return err
}

apiError.QueryID = response.Header.Get("X-Ovh-QueryID")
return apiError
}

Expand Down
15 changes: 15 additions & 0 deletions ovh/ovh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,21 @@ func TestGetResponse(t *testing.T) {
t.Fatalf("getResponse should return an error when failing to decode HTTP Response body. %v", err)
}

// Error with QueryID
responseHeaders := http.Header{}
responseHeaders.Add("X-Ovh-QueryID", "FR.ws-8.5860f657.4632.0180")
err = mockClient.getResponse(&http.Response{
StatusCode: 400,
Body: ioutil.NopCloser(strings.NewReader(`{"code": 400, "message": "Ooops..."}`)),
Header: responseHeaders,
}, &apiInt)
apiErr, ok := err.(*APIError)
if !ok {
t.Fatalf("Client.getResponse error should be an APIError when status is 400 and header QueryID is found. Got '%s' of type %s", err, reflect.TypeOf(err))
}
if apiErr.QueryID != "FR.ws-8.5860f657.4632.0180" {
t.Fatalf("APIError should be filled with a correct QueryID. Got '%s' instead of '%s'", apiErr.QueryID, "FR.ws-8.5860f657.4632.0180")
}
}

func TestConstructors(t *testing.T) {
Expand Down