treewide: 保留httperrors的格式

This commit is contained in:
Yousong Zhou
2018-11-28 07:33:22 +00:00
parent 151da754d3
commit 49382934e5
10 changed files with 19 additions and 22 deletions
+8 -8
View File
@@ -601,7 +601,7 @@ func (dispatcher *DBModelDispatcher) tryGetModelProperty(ctx context.Context, pr
return nil, httperrors.NewInternalServerError("Invald %s return value", funcName)
}
if !outs[0].Bool() {
return nil, httperrors.NewForbiddenError(fmt.Sprintf("%s not allow to get property %s", dispatcher.Keyword(), property))
return nil, httperrors.NewForbiddenError("%s not allow to get property %s", dispatcher.Keyword(), property)
}
funcValue = modelValue.MethodByName(funcName)
@@ -679,7 +679,7 @@ func (dispatcher *DBModelDispatcher) GetSpecific(ctx context.Context, idStr stri
funcValue := modelValue.MethodByName(funcName)
if !funcValue.IsValid() || funcValue.IsNil() {
return nil, httperrors.NewSpecNotFoundError(fmt.Sprintf("%s %s %s not found", dispatcher.Keyword(), idStr, spec))
return nil, httperrors.NewSpecNotFoundError("%s %s %s not found", dispatcher.Keyword(), idStr, spec)
}
outs := funcValue.Call(params)
@@ -690,13 +690,13 @@ func (dispatcher *DBModelDispatcher) GetSpecific(ctx context.Context, idStr stri
}
if !isAllow {
return nil, httperrors.NewForbiddenError(fmt.Sprintf("%s not allow to get spec %s", dispatcher.Keyword(), spec))
return nil, httperrors.NewForbiddenError("%s not allow to get spec %s", dispatcher.Keyword(), spec)
}
funcName := fmt.Sprintf("GetDetails%s", specCamel)
funcValue := modelValue.MethodByName(funcName)
if !funcValue.IsValid() || funcValue.IsNil() {
return nil, httperrors.NewSpecNotFoundError(fmt.Sprintf("%s %s %s not found", dispatcher.Keyword(), idStr, spec))
return nil, httperrors.NewSpecNotFoundError("%s %s %s not found", dispatcher.Keyword(), idStr, spec)
}
outs := funcValue.Call(params)
@@ -740,7 +740,7 @@ func fetchOwnerProjectId(ctx context.Context, manager IModelManager, userCred mc
}
t, _ := TenantCacheManager.FetchTenantByIdOrName(ctx, projId)
if t == nil {
return "", httperrors.NewNotFoundError(fmt.Sprintf("Project %s not found", projId))
return "", httperrors.NewNotFoundError("Project %s not found", projId)
}
return t.GetId(), nil
}
@@ -1094,7 +1094,7 @@ func objectPerformAction(dispatcher *DBModelDispatcher, model IModel, modelValue
isAllow = outs[0].Bool()
}
if !isAllow {
return nil, httperrors.NewForbiddenError(fmt.Sprintf("%s not allow to perform action %s", dispatcher.Keyword(), action))
return nil, httperrors.NewForbiddenError("%s not allow to perform action %s", dispatcher.Keyword(), action)
}
outs := funcValue.Call(params)
@@ -1193,7 +1193,7 @@ func (dispatcher *DBModelDispatcher) Update(ctx context.Context, idStr string, q
isAllow = model.AllowUpdateItem(ctx, userCred)
}
if !isAllow {
return nil, httperrors.NewForbiddenError(fmt.Sprintf("Not allow to update item"))
return nil, httperrors.NewForbiddenError("Not allow to update item")
}
lockman.LockObject(ctx, model)
@@ -1230,7 +1230,7 @@ func deleteItem(manager IModelManager, model IModel, ctx context.Context, userCr
}
if !isAllow {
log.Errorf("not allow to delete")
return nil, httperrors.NewForbiddenError(fmt.Sprintf("%s(%s) not allow to delete", manager.KeywordPlural(), model.GetId()))
return nil, httperrors.NewForbiddenError("%s(%s) not allow to delete", manager.KeywordPlural(), model.GetId())
}
err := model.ValidateDeleteCondition(ctx)
+1 -1
View File
@@ -218,7 +218,7 @@ func (dispatcher *DBJointModelDispatcher) Update(ctx context.Context, id1 string
isAllow = item.AllowUpdateJointItem(ctx, userCred, item)
}
if !isAllow {
return nil, httperrors.NewForbiddenError(fmt.Sprintf("Not allow to update item"))
return nil, httperrors.NewForbiddenError("Not allow to update item")
}
lockman.LockJointObject(ctx, master, slave)
+2 -3
View File
@@ -3,7 +3,6 @@ package db
import (
"context"
"database/sql"
"fmt"
"yunion.io/x/jsonutils"
"yunion.io/x/log"
@@ -64,7 +63,7 @@ func (manager *SStandaloneResourceBaseManager) ValidateName(name string) error {
return httperrors.NewInputParameterError("name starts with letter, and contains letter, number and ._@- only")
}
if manager.NameLength > 0 && len(name) > manager.NameLength {
return httperrors.NewInputParameterError(fmt.Sprintf("name longer than %d", manager.NameLength))
return httperrors.NewInputParameterError("name longer than %d", manager.NameLength)
}
return nil
}
@@ -156,7 +155,7 @@ func (model *SStandaloneResourceBase) SetMetadata(ctx context.Context, key strin
func (model *SStandaloneResourceBase) SetAllMetadata(ctx context.Context, dictstore map[string]interface{}, userCred mcclient.TokenCredential) error {
for k := range dictstore {
if Metadata.IsSystemAdminKey(k) && !userCred.IsSystemAdmin() {
return httperrors.NewNotSufficientPrivilegeError(fmt.Sprintf("not allow to set system key %s", k))
return httperrors.NewNotSufficientPrivilegeError("not allow to set system key %s", k)
}
}
return Metadata.SetAll(ctx, model, dictstore, userCred)
+1 -1
View File
@@ -112,7 +112,7 @@ func (manager *SVirtualJointResourceBaseManager) ListItemFilter(ctx context.Cont
if len(tenant) > 0 {
tc, _ := TenantCacheManager.FetchTenantByIdOrName(ctx, tenant)
if tc == nil {
return nil, httperrors.NewTenantNotFoundError(fmt.Sprintf("tenant %s not found", tenant))
return nil, httperrors.NewTenantNotFoundError("tenant %s not found", tenant)
}
q = q.Filter(sqlchemy.OR(sqlchemy.Equals(masterTable.Field("tenant_id"), tc.GetId()),
sqlchemy.Equals(slaveTable.Field("tenant_id"), tc.GetId())))
+2 -3
View File
@@ -2,7 +2,6 @@ package db
import (
"context"
"fmt"
"strings"
"time"
@@ -85,7 +84,7 @@ func (manager *SVirtualResourceBaseManager) ListItemFilter(ctx context.Context,
if tobj != nil {
q = q.Equals("tenant_id", tobj.GetId())
} else {
return nil, httperrors.NewTenantNotFoundError(fmt.Sprintf("tenant %s not found", tenant))
return nil, httperrors.NewTenantNotFoundError("tenant %s not found", tenant)
}
}
isSystem, err := query.Bool("system")
@@ -208,7 +207,7 @@ func (model *SVirtualResourceBase) PerformChangeOwner(ctx context.Context, userC
}
tobj, _ := TenantCacheManager.FetchTenantByIdOrName(ctx, tenant)
if tobj == nil {
return nil, httperrors.NewTenantNotFoundError(fmt.Sprintf("tenant %s not found", tenant))
return nil, httperrors.NewTenantNotFoundError("tenant %s not found", tenant)
}
q := model.GetModelManager().Query().Equals("name", model.GetName())
q = q.Equals("tenant_id", tobj.GetId())
+1 -1
View File
@@ -93,7 +93,7 @@ func (manager *SHoststorageManager) ValidateCreateData(ctx context.Context, user
}
storageTmp, _ := StorageManager.FetchById(storageId)
if storageTmp == nil {
return nil, httperrors.NewInputParameterError(fmt.Sprintf("invalid storage_id %s", storageId))
return nil, httperrors.NewInputParameterError("invalid storage_id %s", storageId)
}
storage := storageTmp.(*SStorage)
if storage.StorageType == STORAGE_RBD {
+1 -1
View File
@@ -276,7 +276,7 @@ func (self *SNetwork) GetFreeIP(ctx context.Context, userCred mcclient.TokenCred
if reserved {
rip := ReservedipManager.GetReservedIP(self, candidate)
if rip == nil {
return "", httperrors.NewInsufficientResourceError(fmt.Sprintf("Reserved address %s not found", candidate))
return "", httperrors.NewInsufficientResourceError("Reserved address %s not found", candidate)
}
rip.Release(ctx, userCred, self)
return candidate, nil
+1 -2
View File
@@ -2,7 +2,6 @@ package models
import (
"context"
"fmt"
"yunion.io/x/jsonutils"
"yunion.io/x/log"
@@ -131,7 +130,7 @@ func (manager *SReservedipManager) ListItemFilter(ctx context.Context, q *sqlche
if len(network) > 0 {
netObj, _ := NetworkManager.FetchByIdOrName(userCred, network)
if netObj == nil {
return nil, httperrors.NewResourceNotFoundError(fmt.Sprintf("network %s not found", network))
return nil, httperrors.NewResourceNotFoundError("network %s not found", network)
}
q = q.Equals("network_id", netObj.GetId())
}
+1 -1
View File
@@ -109,7 +109,7 @@ func (manager *SSecurityGroupRuleManager) ListItemFilter(ctx context.Context, q
if secgroup, _ := SecurityGroupManager.FetchByIdOrName(userCred, defsecgroup); secgroup != nil {
sql = sql.Equals("secgroup_id", secgroup.GetId())
} else {
return nil, httperrors.NewNotFoundError(fmt.Sprintf("Security Group %s not found", defsecgroup))
return nil, httperrors.NewNotFoundError("Security Group %s not found", defsecgroup)
}
}
for _, field := range []string{"direction", "action", "protocol"} {
+1 -1
View File
@@ -240,7 +240,7 @@ func (this *DomainManager) DoDomainConfigDelete(s *mcclient.ClientSession, param
log.Errorf("user list got error: %v", err)
return ret, httperrors.NewInternalServerError("fetching user list failed: %s", err)
} else if len(result.Data) > 0 {
return ret, httperrors.NewForbiddenError(fmt.Sprintf("cannot delete: there still exists %d user related with domain %s.", len(result.Data), objId))
return ret, httperrors.NewForbiddenError("cannot delete: there still exists %d user related with domain %s.", len(result.Data), objId)
}
}