Change Format of API Error (#784)
This is a wire breaking change for json errors since we have removed and renamed a few fields, and changed part of the structure of the returned json error. * Remove redundant fields in Status, details.error_id, details.TraceId and details.request_id from API errors. * Added wrapped errors and "ops" field to indicate the internal operation of the errors returned by the API. * Added error cli error reporting of Op and wrapped errors.
This commit is contained in:
1 parent
18ea39b237
commit
aa4157639c
48 files changed
+742
-728
No files matched your search
+23
-28
@@ -26,22 +26,24 @@ type Host struct {
|
||||
HostSetIds []string `json:"host_set_ids,omitempty"`
|
||||
Attributes map[string]interface{} `json:"attributes,omitempty"`
|
||||
|
||||
responseBody *bytes.Buffer
|
||||
responseMap map[string]interface{}
|
||||
response *api.Response
|
||||
}
|
||||
|
||||
func (n Host) ResponseBody() *bytes.Buffer {
|
||||
return n.responseBody
|
||||
return n.response.Body
|
||||
}
|
||||
|
||||
func (n Host) ResponseMap() map[string]interface{} {
|
||||
return n.responseMap
|
||||
return n.response.Map
|
||||
}
|
||||
|
||||
func (n Host) ResponseStatus() int {
|
||||
return n.response.HttpResponse().StatusCode
|
||||
}
|
||||
|
||||
type HostReadResult struct {
|
||||
Item *Host
|
||||
responseBody *bytes.Buffer
|
||||
responseMap map[string]interface{}
|
||||
Item *Host
|
||||
response *api.Response
|
||||
}
|
||||
|
||||
func (n HostReadResult) GetItem() interface{} {
|
||||
@@ -49,33 +51,31 @@ func (n HostReadResult) GetItem() interface{} {
|
||||
}
|
||||
|
||||
func (n HostReadResult) GetResponseBody() *bytes.Buffer {
|
||||
return n.responseBody
|
||||
return n.response.Body
|
||||
}
|
||||
|
||||
func (n HostReadResult) GetResponseMap() map[string]interface{} {
|
||||
return n.responseMap
|
||||
return n.response.Map
|
||||
}
|
||||
|
||||
type HostCreateResult = HostReadResult
|
||||
type HostUpdateResult = HostReadResult
|
||||
|
||||
type HostDeleteResult struct {
|
||||
responseBody *bytes.Buffer
|
||||
responseMap map[string]interface{}
|
||||
response *api.Response
|
||||
}
|
||||
|
||||
func (n HostDeleteResult) GetResponseBody() *bytes.Buffer {
|
||||
return n.responseBody
|
||||
return n.response.Body
|
||||
}
|
||||
|
||||
func (n HostDeleteResult) GetResponseMap() map[string]interface{} {
|
||||
return n.responseMap
|
||||
return n.response.Map
|
||||
}
|
||||
|
||||
type HostListResult struct {
|
||||
Items []*Host
|
||||
responseBody *bytes.Buffer
|
||||
responseMap map[string]interface{}
|
||||
Items []*Host
|
||||
response *api.Response
|
||||
}
|
||||
|
||||
func (n HostListResult) GetItems() interface{} {
|
||||
@@ -83,11 +83,11 @@ func (n HostListResult) GetItems() interface{} {
|
||||
}
|
||||
|
||||
func (n HostListResult) GetResponseBody() *bytes.Buffer {
|
||||
return n.responseBody
|
||||
return n.response.Body
|
||||
}
|
||||
|
||||
func (n HostListResult) GetResponseMap() map[string]interface{} {
|
||||
return n.responseMap
|
||||
return n.response.Map
|
||||
}
|
||||
|
||||
// Client is a client for this collection
|
||||
@@ -148,8 +148,7 @@ func (c *Client) Create(ctx context.Context, hostCatalogId string, opt ...Option
|
||||
if apiErr != nil {
|
||||
return nil, apiErr
|
||||
}
|
||||
target.responseBody = resp.Body
|
||||
target.responseMap = resp.Map
|
||||
target.response = resp
|
||||
return target, nil
|
||||
}
|
||||
|
||||
@@ -190,8 +189,7 @@ func (c *Client) Read(ctx context.Context, hostId string, opt ...Option) (*HostR
|
||||
if apiErr != nil {
|
||||
return nil, apiErr
|
||||
}
|
||||
target.responseBody = resp.Body
|
||||
target.responseMap = resp.Map
|
||||
target.response = resp
|
||||
return target, nil
|
||||
}
|
||||
|
||||
@@ -254,8 +252,7 @@ func (c *Client) Update(ctx context.Context, hostId string, version uint32, opt
|
||||
if apiErr != nil {
|
||||
return nil, apiErr
|
||||
}
|
||||
target.responseBody = resp.Body
|
||||
target.responseMap = resp.Map
|
||||
target.response = resp
|
||||
return target, nil
|
||||
}
|
||||
|
||||
@@ -296,8 +293,7 @@ func (c *Client) Delete(ctx context.Context, hostId string, opt ...Option) (*Hos
|
||||
}
|
||||
|
||||
target := &HostDeleteResult{
|
||||
responseBody: resp.Body,
|
||||
responseMap: resp.Map,
|
||||
response: resp,
|
||||
}
|
||||
return target, nil
|
||||
}
|
||||
@@ -339,7 +335,6 @@ func (c *Client) List(ctx context.Context, hostCatalogId string, opt ...Option)
|
||||
if apiErr != nil {
|
||||
return nil, apiErr
|
||||
}
|
||||
target.responseBody = resp.Body
|
||||
target.responseMap = resp.Map
|
||||
target.response = resp
|
||||
return target, nil
|
||||
}
|
||||
Reference in new issue
Block a user