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:
Todd Knight authored and GitHub committed 2020-12-07 14:25:16 -07:00
1 parent 18ea39b237
commit aa4157639c
48 files changed
+742 -728

No files matched your search

+18 -12
View File
@@ -136,20 +136,13 @@ func WrapMap(prefixSpaces, maxLengthOverride int, input map[string]interface{})
func PrintApiError(in *api.Error) string {
nonAttributeMap := map[string]interface{}{
"Status": in.Status,
"Code": in.Code,
"Status": in.ResponseStatus(),
"Kind": in.Kind,
"Message": in.Message,
}
if in.Details != nil {
if in.Details.TraceId != "" {
nonAttributeMap["Trace ID"] = in.Details.TraceId
}
if in.Details.RequestId != "" {
nonAttributeMap["Request ID"] = in.Details.RequestId
}
if in.Details.ErrorId != "" {
nonAttributeMap["Error ID"] = in.Details.ErrorId
}
if in.Op != "" {
nonAttributeMap["Operation"] = in.Op
}
maxLength := MaxAttributesLength(nonAttributeMap, nil, nil)
@@ -161,6 +154,19 @@ func PrintApiError(in *api.Error) string {
}
if in.Details != nil {
if len(in.Details.WrappedErrors) > 0 {
ret = append(ret,
"",
" Wrapped Errors:",
)
for _, we := range in.Details.WrappedErrors {
ret = append(ret,
fmt.Sprintf(" Message: %s", we.Message),
fmt.Sprintf(" Operation: %s", we.Op),
)
}
}
if len(in.Details.RequestFields) > 0 {
ret = append(ret,
"",
+1 -1
View File
@@ -266,7 +266,7 @@ func (c *Command) Run(args []string) int {
result, err = accountClient.Read(c.Context, c.FlagId, opts...)
case "delete":
_, err = accountClient.Delete(c.Context, c.FlagId, opts...)
if apiErr := api.AsServerError(err); apiErr != nil && apiErr.Status == int32(http.StatusNotFound) {
if apiErr := api.AsServerError(err); apiErr != nil && apiErr.ResponseStatus() == http.StatusNotFound {
existed = false
err = nil
}
@@ -156,7 +156,7 @@ func (c *Command) Run(args []string) int {
result, err = authmethodClient.Read(c.Context, c.FlagId, opts...)
case "delete":
_, err = authmethodClient.Delete(c.Context, c.FlagId, opts...)
if apiErr := api.AsServerError(err); apiErr != nil && apiErr.Status == int32(http.StatusNotFound) {
if apiErr := api.AsServerError(err); apiErr != nil && apiErr.ResponseStatus() == http.StatusNotFound {
existed = false
err = nil
}
@@ -99,7 +99,7 @@ func (c *Command) Run(args []string) int {
result, err = authtokenClient.Read(c.Context, c.FlagId)
case "delete":
_, err = authtokenClient.Delete(c.Context, c.FlagId)
if apiErr := api.AsServerError(err); apiErr != nil && apiErr.Status == int32(http.StatusNotFound) {
if apiErr := api.AsServerError(err); apiErr != nil && apiErr.ResponseStatus() == http.StatusNotFound {
existed = false
err = nil
}
+1 -1
View File
@@ -170,7 +170,7 @@ func (c *Command) Run(args []string) int {
result, err = groupClient.Read(c.Context, c.FlagId, opts...)
case "delete":
_, err = groupClient.Delete(c.Context, c.FlagId, opts...)
if apiErr := api.AsServerError(err); apiErr != nil && apiErr.Status == int32(http.StatusNotFound) {
if apiErr := api.AsServerError(err); apiErr != nil && apiErr.ResponseStatus() == http.StatusNotFound {
existed = false
err = nil
}
@@ -157,7 +157,7 @@ func (c *Command) Run(args []string) int {
result, err = hostcatalogClient.Read(c.Context, c.FlagId, opts...)
case "delete":
_, err = hostcatalogClient.Delete(c.Context, c.FlagId, opts...)
if apiErr := api.AsServerError(err); apiErr != nil && apiErr.Status == int32(http.StatusNotFound) {
if apiErr := api.AsServerError(err); apiErr != nil && apiErr.ResponseStatus() == http.StatusNotFound {
existed = false
err = nil
}
+1 -1
View File
@@ -156,7 +156,7 @@ func (c *Command) Run(args []string) int {
result, err = hostClient.Read(c.Context, c.FlagId, opts...)
case "delete":
_, err = hostClient.Delete(c.Context, c.FlagId, opts...)
if apiErr := api.AsServerError(err); apiErr != nil && apiErr.Status == int32(http.StatusNotFound) {
if apiErr := api.AsServerError(err); apiErr != nil && apiErr.ResponseStatus() == http.StatusNotFound {
existed = false
err = nil
}
+1 -1
View File
@@ -245,7 +245,7 @@ func (c *Command) Run(args []string) int {
result, err = hostsetClient.Read(c.Context, c.FlagId, opts...)
case "delete":
_, err = hostsetClient.Delete(c.Context, c.FlagId, opts...)
if apiErr := api.AsServerError(err); apiErr != nil && apiErr.Status == int32(http.StatusNotFound) {
if apiErr := api.AsServerError(err); apiErr != nil && apiErr.ResponseStatus() == http.StatusNotFound {
existed = false
err = nil
}
+1 -1
View File
@@ -217,7 +217,7 @@ func (c *Command) Run(args []string) int {
result, err = roleClient.Read(c.Context, c.FlagId, opts...)
case "delete":
_, err = roleClient.Delete(c.Context, c.FlagId, opts...)
if apiErr := api.AsServerError(err); apiErr != nil && apiErr.Status == int32(http.StatusNotFound) {
if apiErr := api.AsServerError(err); apiErr != nil && apiErr.ResponseStatus() == http.StatusNotFound {
existed = false
err = nil
}
+1 -1
View File
@@ -156,7 +156,7 @@ func (c *Command) Run(args []string) int {
result, err = scopeClient.Read(c.Context, c.FlagId, opts...)
case "delete":
_, err = scopeClient.Delete(c.Context, c.FlagId, opts...)
if apiErr := api.AsServerError(err); apiErr != nil && apiErr.Status == int32(http.StatusNotFound) {
if apiErr := api.AsServerError(err); apiErr != nil && apiErr.ResponseStatus() == http.StatusNotFound {
existed = false
err = nil
}
+1 -1
View File
@@ -345,7 +345,7 @@ func (c *Command) Run(args []string) int {
result, err = targetClient.Read(c.Context, c.FlagId, opts...)
case "delete":
_, err = targetClient.Delete(c.Context, c.FlagId, opts...)
if apiErr := api.AsServerError(err); apiErr != nil && apiErr.Status == int32(http.StatusNotFound) {
if apiErr := api.AsServerError(err); apiErr != nil && apiErr.ResponseStatus() == http.StatusNotFound {
existed = false
err = nil
}
+1 -1
View File
@@ -170,7 +170,7 @@ func (c *Command) Run(args []string) int {
result, err = userClient.Read(c.Context, c.FlagId, opts...)
case "delete":
_, err = userClient.Delete(c.Context, c.FlagId, opts...)
if apiErr := api.AsServerError(err); apiErr != nil && apiErr.Status == int32(http.StatusNotFound) {
if apiErr := api.AsServerError(err); apiErr != nil && apiErr.ResponseStatus() == http.StatusNotFound {
existed = false
err = nil
}