Skip to content
This repository has been archived by the owner on Jan 17, 2025. It is now read-only.

Commit

Permalink
api: include response code in error messages
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitrios Karagiannis <[email protected]>
  • Loading branch information
alkar committed Feb 12, 2020
1 parent be3329f commit ac6bae0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions megaport/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ func (c *Client) do(req *http.Request, data interface{}) error {
}
err := responseDataToError(r.Data)
if err != nil {
return fmt.Errorf("megaport-api: %s: %w", r.Message, err)
return fmt.Errorf("megaport-api (%d): %s: %w", resp.StatusCode, r.Message, err)
} else {
return fmt.Errorf("megaport-api: %s", r.Message)
return fmt.Errorf("megaport-api (%d): %s", resp.StatusCode, r.Message)
}
}
return parseResponseBody(resp, &megaportResponse{Data: data})
Expand Down
12 changes: 6 additions & 6 deletions megaport/api/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,27 +90,27 @@ func TestClient_responseDataToError(t *testing.T) {
}{
{
p: `{"message":"foo"}`,
e: `megaport-api: foo`,
e: `megaport-api (500): foo`,
},
{
p: `{"message":"foo","data":"bar"}`,
e: `megaport-api: foo: bar`,
e: `megaport-api (500): foo: bar`,
},
{
p: `{"message":"foo","data":["bar","baz"]}`,
e: `megaport-api: foo: 2 errors: ['bar', 'baz']`,
e: `megaport-api (500): foo: 2 errors: ['bar', 'baz']`,
},
{
p: `{"message":"foo","data":{"a":"b"}}`,
e: `megaport-api: foo: a="b"`,
e: `megaport-api (500): foo: a="b"`,
},
{
p: `{"message":"foo","data":{"c":5}}`,
e: `megaport-api: foo: c=5`,
e: `megaport-api (500): foo: c=5`,
},
{
p: `{"message":"foo","data":true}`,
e: `megaport-api: foo: cannot process error data of type bool: true`,
e: `megaport-api (500): foo: cannot process error data of type bool: true`,
},
}
c, s := testClientServer(func(w http.ResponseWriter, r *http.Request) {
Expand Down

0 comments on commit ac6bae0

Please sign in to comment.