Skip to content

Commit

Permalink
Improve megaport api 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 Oct 11, 2019
1 parent 1d76f7a commit a09b86e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion megaport/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,12 @@ func (c *Client) do(req *http.Request, data interface{}) error {
if err := parseResponseBody(resp, &r); err != nil {
return err
}
return fmt.Errorf("megaport-api: %s: %w", r.Message, responseDataToError(r.Data))
err := responseDataToError(r.Data)
if err != nil {
return fmt.Errorf("megaport-api: %s: %w", r.Message, err)
} else {
return fmt.Errorf("megaport-api: %s", r.Message)
}
}
return parseResponseBody(resp, &megaportResponse{Data: data})
}
Expand All @@ -209,6 +214,8 @@ func responseDataToError(d interface{}) error {
errors[i] = responseDataToError(v).Error()
}
return fmt.Errorf("%d errors: ['%s']", len(e), strings.Join(errors, "', '"))
case nil:
return nil
default:
return fmt.Errorf("cannot process error data of type %T: %#v", e, e)
}
Expand Down

0 comments on commit a09b86e

Please sign in to comment.