fix: simplify object delete-fail-reason message

This commit is contained in:
Qiu Jian
2019-11-08 22:45:19 +08:00
parent cf4bb0e642
commit d27f718e3e
3 changed files with 14 additions and 3 deletions
+2 -2
View File
@@ -670,14 +670,14 @@ func getModelExtraDetails(item IModel, ctx context.Context, extra *jsonutils.JSO
err := item.ValidateDeleteCondition(ctx)
if err != nil {
extra.Add(jsonutils.JSONFalse, "can_delete")
extra.Add(jsonutils.NewString(err.Error()), "delete_fail_reason")
extra.Add(jsonutils.NewString(httputils.ErrorMsg(err)), "delete_fail_reason")
} else {
extra.Add(jsonutils.JSONTrue, "can_delete")
}
err = item.ValidateUpdateCondition(ctx)
if err != nil {
extra.Add(jsonutils.JSONFalse, "can_update")
extra.Add(jsonutils.NewString(err.Error()), "update_fail_reason")
extra.Add(jsonutils.NewString(httputils.ErrorMsg(err)), "update_fail_reason")
} else {
extra.Add(jsonutils.JSONTrue, "can_update")
}
+1 -1
View File
@@ -2338,7 +2338,7 @@ func (self *SHost) getMoreDetails(ctx context.Context, extra *jsonutils.JSONDict
extra.Add(jsonutils.JSONTrue, "can_prepare")
} else {
extra.Add(jsonutils.JSONFalse, "can_prepare")
extra.Add(jsonutils.NewString(err.Error()), "prepare_fail_reason")
extra.Add(jsonutils.NewString(httputils.ErrorMsg(err)), "prepare_fail_reason")
}
}
+11
View File
@@ -92,6 +92,17 @@ func ErrorCode(err error) int {
return -1
}
func ErrorMsg(err error) string {
if err == nil {
return ""
}
switch je := err.(type) {
case *JSONClientError:
return je.Details
}
return err.Error()
}
func GetAddrPort(urlStr string) (string, int, error) {
parts, err := url.Parse(urlStr)
if err != nil {