From 58ee33c3f09792838d79420703fc560db07c6258 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=88=E8=BD=A9?= Date: Thu, 7 Mar 2019 15:42:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=B8=80=E4=BA=9B=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E4=BF=A1=E6=81=AF=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/cloudcommon/db/virtualresource.go | 2 +- pkg/compute/hostdrivers/managedvirtual.go | 3 +-- pkg/compute/models/cloudproviders.go | 2 +- pkg/compute/models/cloudregions.go | 2 +- pkg/compute/models/dynamicschedtags.go | 5 +++-- pkg/compute/models/elasticips.go | 6 +++--- pkg/compute/models/guest_actions.go | 24 ++++++++++----------- pkg/compute/models/guests.go | 4 ++-- pkg/compute/models/host_recycle.go | 2 +- pkg/compute/models/loadbalancerlisteners.go | 4 ++-- pkg/compute/models/networks.go | 4 ++-- pkg/compute/models/schedpolicies.go | 2 +- pkg/compute/models/secgrouprules.go | 2 +- pkg/compute/models/secgroups.go | 2 +- pkg/compute/models/storagecaches.go | 2 +- pkg/compute/models/vpcs.go | 9 +++----- pkg/compute/models/wires.go | 2 +- pkg/hostman/guesthandlers/guesthandler.go | 2 +- pkg/httperrors/errors.go | 1 + pkg/image/models/images.go | 2 +- pkg/util/aliyun/storagecache.go | 3 +-- 21 files changed, 41 insertions(+), 44 deletions(-) diff --git a/pkg/cloudcommon/db/virtualresource.go b/pkg/cloudcommon/db/virtualresource.go index 63bfa5fa5f..5d1a57b78a 100644 --- a/pkg/cloudcommon/db/virtualresource.go +++ b/pkg/cloudcommon/db/virtualresource.go @@ -207,7 +207,7 @@ func (model *SVirtualResourceBase) AllowPerformChangeOwner(ctx context.Context, func (model *SVirtualResourceBase) PerformChangeOwner(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { tenant := jsonutils.GetAnyString(data, []string{"project", "tenant", "project_id", "tenant_id"}) if len(tenant) == 0 { - return nil, httperrors.NewInputParameterError("missing parameter tenant") + return nil, httperrors.NewMissingParameterError("tenant_id") } tobj, _ := TenantCacheManager.FetchTenantByIdOrName(ctx, tenant) if tobj == nil { diff --git a/pkg/compute/hostdrivers/managedvirtual.go b/pkg/compute/hostdrivers/managedvirtual.go index 331010df04..525581f961 100644 --- a/pkg/compute/hostdrivers/managedvirtual.go +++ b/pkg/compute/hostdrivers/managedvirtual.go @@ -13,7 +13,6 @@ import ( "yunion.io/x/onecloud/pkg/cloudprovider" "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/compute/options" - "yunion.io/x/onecloud/pkg/httperrors" ) type SManagedVirtualizationHostDriver struct { @@ -147,7 +146,7 @@ func (self *SManagedVirtualizationHostDriver) RequestSaveUploadImageOnHost(ctx c } iStoragecache := iStorage.GetIStoragecache() if iStoragecache == nil { - return httperrors.NewResourceNotFoundError("fail to find iStoragecache for storage: %s", iStorage.GetName()) + return fmt.Errorf("fail to find iStoragecache for storage: %s", iStorage.GetName()) } taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) { snapshot, err := iDisk.CreateISnapshot(ctx, fmt.Sprintf("Snapshot-%s", imageId), "PrepareSaveImage") diff --git a/pkg/compute/models/cloudproviders.go b/pkg/compute/models/cloudproviders.go index 588060a2b4..1d709acf10 100644 --- a/pkg/compute/models/cloudproviders.go +++ b/pkg/compute/models/cloudproviders.go @@ -467,7 +467,7 @@ func (self *SCloudprovider) AllowPerformChangeProject(ctx context.Context, userC func (self *SCloudprovider) PerformChangeProject(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { project, err := data.GetString("project") if err != nil { - return nil, httperrors.NewInputParameterError("Missing project parameter") + return nil, httperrors.NewMissingParameterError("project") } tenant, err := db.TenantCacheManager.FetchTenantByIdOrName(ctx, project) diff --git a/pkg/compute/models/cloudregions.go b/pkg/compute/models/cloudregions.go index 2ebd8a3da4..79aebb863e 100644 --- a/pkg/compute/models/cloudregions.go +++ b/pkg/compute/models/cloudregions.go @@ -299,7 +299,7 @@ func (self *SCloudregion) PerformDefaultVpc(ctx context.Context, userCred mcclie } vpcStr, _ := data.GetString("vpc") if len(vpcStr) == 0 { - return nil, httperrors.NewInputParameterError("no vpc id") + return nil, httperrors.NewMissingParameterError("vpc") } findVpc := false for _, vpc := range vpcs { diff --git a/pkg/compute/models/dynamicschedtags.go b/pkg/compute/models/dynamicschedtags.go index f80008ebb8..d337916ca2 100644 --- a/pkg/compute/models/dynamicschedtags.go +++ b/pkg/compute/models/dynamicschedtags.go @@ -7,6 +7,7 @@ import ( "yunion.io/x/log" "database/sql" + "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/httperrors" "yunion.io/x/onecloud/pkg/mcclient" @@ -66,7 +67,7 @@ func (self *SDynamicschedtag) AllowDeleteItem(ctx context.Context, userCred mccl func validateDynamicSchedtagInputData(data *jsonutils.JSONDict, create bool) error { condStr := jsonutils.GetAnyString(data, []string{"condition"}) if len(condStr) == 0 && create { - return httperrors.NewInputParameterError("empty condition") + return httperrors.NewMissingParameterError("condition") } if len(condStr) > 0 && !conditionparser.IsValid(condStr) { return httperrors.NewInputParameterError("invalid condition") @@ -74,7 +75,7 @@ func validateDynamicSchedtagInputData(data *jsonutils.JSONDict, create bool) err schedStr := jsonutils.GetAnyString(data, []string{"schedtag", "schedtag_id"}) if len(schedStr) == 0 && create { - return httperrors.NewInputParameterError("missing schedtag") + return httperrors.NewMissingParameterError("schedtag_id") } if len(schedStr) > 0 { schedObj, err := SchedtagManager.FetchByIdOrName(nil, schedStr) diff --git a/pkg/compute/models/elasticips.go b/pkg/compute/models/elasticips.go index 5ae96192ba..ac697f0e9d 100644 --- a/pkg/compute/models/elasticips.go +++ b/pkg/compute/models/elasticips.go @@ -457,7 +457,7 @@ func (manager *SElasticipManager) getEipByExtEip(ctx context.Context, userCred m func (manager *SElasticipManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerProjId string, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) { regionStr := jsonutils.GetAnyString(data, []string{"region", "region_id"}) if len(regionStr) == 0 { - return nil, httperrors.NewInputParameterError("Missing region/region_id") + return nil, httperrors.NewMissingParameterError("region_id") } region, err := CloudregionManager.FetchByIdOrName(nil, regionStr) if err != nil { @@ -471,7 +471,7 @@ func (manager *SElasticipManager) ValidateCreateData(ctx context.Context, userCr managerStr := jsonutils.GetAnyString(data, []string{"manager", "manager_id"}) if len(managerStr) == 0 { - return nil, httperrors.NewInputParameterError("Missing manager/manager_id") + return nil, httperrors.NewMissingParameterError("manager_id") } provider, err := CloudproviderManager.FetchByIdOrName(nil, managerStr) @@ -577,7 +577,7 @@ func (self *SElasticip) PerformAssociate(ctx context.Context, userCred mcclient. instanceId := jsonutils.GetAnyString(data, []string{"instance", "instance_id"}) if len(instanceId) == 0 { - return nil, httperrors.NewInputParameterError("Missing instance_id") + return nil, httperrors.NewMissingParameterError("instance_id") } instanceType := jsonutils.GetAnyString(data, []string{"instance_type"}) if len(instanceType) == 0 { diff --git a/pkg/compute/models/guest_actions.go b/pkg/compute/models/guest_actions.go index 433e94cca0..10aa3429af 100644 --- a/pkg/compute/models/guest_actions.go +++ b/pkg/compute/models/guest_actions.go @@ -249,7 +249,7 @@ func (self *SGuest) PerformLiveMigrate(ctx context.Context, userCred mcclient.To return nil, err } if image.DiskFormat != "qcow2" { - return nil, httperrors.NewBadRequestError("Live migrate only support image fromat qocw2") + return nil, httperrors.NewBadRequestError("Live migrate only support image format qocw2") } if utils.IsInStringArray(self.Status, []string{VM_RUNNING, VM_SUSPEND}) { cdrom := self.getCdrom() @@ -1369,7 +1369,7 @@ func (self *SGuest) PerformChangeIpaddr(ctx context.Context, userCred mcclient.T netDesc, err := data.Get("net_desc") if err != nil { log.Errorf("net_desc not found") - return nil, httperrors.NewInputParameterError("missing net_desc") + return nil, httperrors.NewMissingParameterError("net_desc") } conf, err := parseNetworkInfo(userCred, netDesc) if err != nil { @@ -2008,7 +2008,7 @@ func (self *SGuest) AllowPerformSendkeys(ctx context.Context, userCred mcclient. func (self *SGuest) PerformSendkeys(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { if self.Hypervisor != HYPERVISOR_KVM { - return nil, httperrors.NewUnsupportOperationError("Not allow for hypervisor %s", self.Hypervisor) + return nil, httperrors.NewNotAcceptableError("Not allow for hypervisor %s", self.Hypervisor) } if self.Status != VM_RUNNING { return nil, httperrors.NewInvalidStatusError("Cannot send keys in status %s", self.Status) @@ -2096,7 +2096,7 @@ func (self *SGuest) PerformAssociateEip(ctx context.Context, userCred mcclient.T } eipStr := jsonutils.GetAnyString(data, []string{"eip", "eip_id"}) if len(eipStr) == 0 { - return nil, httperrors.NewInputParameterError("missing eip or eip_id") + return nil, httperrors.NewMissingParameterError("eip_id") } eipObj, err := ElasticipManager.FetchByIdOrName(userCred, eipStr) if err != nil { @@ -2178,7 +2178,7 @@ func (self *SGuest) AllowPerformCreateEip(ctx context.Context, userCred mcclient func (self *SGuest) PerformCreateEip(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { bw, err := data.Int("bandwidth") if err != nil { - return nil, httperrors.NewInputParameterError("Missing bandwidth") + return nil, httperrors.NewMissingParameterError("bandwidth") } chargeType, _ := data.GetString("charge_type") @@ -2238,7 +2238,7 @@ func (self *SGuest) AllowPerformUserData(ctx context.Context, userCred mcclient. func (self *SGuest) PerformUserData(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { userData, err := data.GetString("user_data") if err != nil { - return nil, httperrors.NewInputParameterError("missing user_data %s", err) + return nil, httperrors.NewMissingParameterError("user_data") } err = self.setUserData(ctx, userCred, userData) if err != nil { @@ -2297,7 +2297,7 @@ func (manager *SGuestManager) AllowPerformDirtyServerStart(ctx context.Context, func (manager *SGuestManager) PerformDirtyServerStart(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { guestId, err := data.GetString("guest_id") if err != nil { - return nil, httperrors.NewBadRequestError("Missing guest_id") + return nil, httperrors.NewMissingParameterError("guest_id") } guest := manager.FetchGuestById(guestId) if guest == nil { @@ -2305,7 +2305,7 @@ func (manager *SGuestManager) PerformDirtyServerStart(ctx context.Context, userC } hostId, _ := data.GetString("host_id") if len(hostId) == 0 { - return nil, httperrors.NewBadRequestError("Missing host_id or host id is nil?") + return nil, httperrors.NewMissingParameterError("host_id") } if guest.HostId == hostId { @@ -2327,7 +2327,7 @@ func (manager *SGuestManager) AllowPerformDirtyServerVerify(ctx context.Context, func (manager *SGuestManager) PerformDirtyServerVerify(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { guestId, err := data.GetString("guest_id") if err != nil { - return nil, httperrors.NewBadRequestError("Missing guest_id") + return nil, httperrors.NewMissingParameterError("guest_id") } guest := manager.FetchGuestById(guestId) if guest == nil { @@ -2335,7 +2335,7 @@ func (manager *SGuestManager) PerformDirtyServerVerify(ctx context.Context, user } hostId, _ := data.GetString("host_id") if len(hostId) == 0 { - return nil, httperrors.NewBadRequestError("Missing host_id or host id is nil?") + return nil, httperrors.NewMissingParameterError("host_id") } if guest.HostId != hostId && guest.BackupHostId != hostId { @@ -2485,7 +2485,7 @@ func (self *SGuest) AllowPerformSetExtraOption(ctx context.Context, userCred mcc func (self *SGuest) PerformSetExtraOption(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { key, err := data.GetString("key") if err != nil { - return nil, httperrors.NewBadRequestError("Option key required") + return nil, httperrors.NewMissingParameterError("key") } value, _ := data.GetString("value") extraOptions := self.GetExtraOptions(userCred) @@ -2513,7 +2513,7 @@ func (self *SGuest) AllowPerformDelExtraOption(ctx context.Context, userCred mcc func (self *SGuest) PerformDelExtraOption(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { key, err := data.GetString("key") if err != nil { - return nil, httperrors.NewBadRequestError("Option key required") + return nil, httperrors.NewMissingParameterError("key") } extraOptions := self.GetExtraOptions(userCred) extraOptions.Remove(key) diff --git a/pkg/compute/models/guests.go b/pkg/compute/models/guests.go index 7e7c1dd6dd..df3b6085f5 100644 --- a/pkg/compute/models/guests.go +++ b/pkg/compute/models/guests.go @@ -777,7 +777,7 @@ func (self *SGuest) ValidateUpdateData(ctx context.Context, userCred mcclient.To if data.Contains("name") { if name, _ := data.GetString("name"); len(name) < 2 { - return nil, httperrors.NewInputParameterError("name is to short") + return nil, httperrors.NewInputParameterError("name is too short") } } return self.SVirtualResourceBase.ValidateUpdateData(ctx, userCred, query, data) @@ -885,7 +885,7 @@ func (manager *SGuestManager) ValidateCreateData(ctx context.Context, userCred m } if vmemSize == 0 { - return nil, httperrors.NewInputParameterError("Missing memory size") + return nil, httperrors.NewMissingParameterError("vmem_size") } if vcpuCount == 0 { vcpuCount = 1 diff --git a/pkg/compute/models/host_recycle.go b/pkg/compute/models/host_recycle.go index ad44d1a900..36967ecb95 100644 --- a/pkg/compute/models/host_recycle.go +++ b/pkg/compute/models/host_recycle.go @@ -690,7 +690,7 @@ func (self *SHost) AllowPerformRenewPrepaidRecycle(ctx context.Context, userCred func (self *SHost) PerformRenewPrepaidRecycle(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { durationStr := jsonutils.GetAnyString(data, []string{"duration"}) if len(durationStr) == 0 { - return nil, httperrors.NewInputParameterError("missing duration") + return nil, httperrors.NewMissingParameterError("duration") } bc, err := billing.ParseBillingCycle(durationStr) diff --git a/pkg/compute/models/loadbalancerlisteners.go b/pkg/compute/models/loadbalancerlisteners.go index 95abad6f8d..4a68f7ceaa 100644 --- a/pkg/compute/models/loadbalancerlisteners.go +++ b/pkg/compute/models/loadbalancerlisteners.go @@ -306,10 +306,10 @@ func (man *SLoadbalancerListenerManager) checkTypeV(listenerType string) validat func (man *SLoadbalancerListenerManager) validateAcl(aclStatusV *validators.ValidatorStringChoices, aclTypeV *validators.ValidatorStringChoices, aclV *validators.ValidatorModelIdOrName, data *jsonutils.JSONDict) error { if aclStatusV.Value == consts.LB_BOOL_ON { if aclV.Model == nil { - return httperrors.NewInputParameterError("missing acl") + return httperrors.NewMissingParameterError("acl") } if len(aclTypeV.Value) == 0 { - return httperrors.NewInputParameterError("missing acl_type") + return httperrors.NewMissingParameterError("acl_type") } } else { data.Set("acl_id", jsonutils.NewString("")) diff --git a/pkg/compute/models/networks.go b/pkg/compute/models/networks.go index 8cfb067641..bd17f5e136 100644 --- a/pkg/compute/models/networks.go +++ b/pkg/compute/models/networks.go @@ -1125,11 +1125,11 @@ func (manager *SNetworkManager) ValidateCreateData(ctx context.Context, userCred wireId, _ := data.GetString("wire_id") if len(wireId) == 0 { - return nil, httperrors.NewInputParameterError("missing wire_id") + return nil, httperrors.NewMissingParameterError("wire_id") } wire := WireManager.FetchWireById(wireId) if wire == nil { - return nil, httperrors.NewInputParameterError("wire_id %s not valid", wireId) + return nil, httperrors.NewResourceNotFoundError("wire %s not found", wireId) } vpc := wire.getVpc() if vpc == nil { diff --git a/pkg/compute/models/schedpolicies.go b/pkg/compute/models/schedpolicies.go index 1b5e820af1..5f2c957342 100644 --- a/pkg/compute/models/schedpolicies.go +++ b/pkg/compute/models/schedpolicies.go @@ -50,7 +50,7 @@ func validateSchedpolicyInputData(data *jsonutils.JSONDict, create bool) error { strategyStr := jsonutils.GetAnyString(data, []string{"strategy"}) if len(strategyStr) == 0 && create { - return httperrors.NewInputParameterError("missing strategy") + return httperrors.NewMissingParameterError("strategy") } if len(strategyStr) > 0 && !utils.IsInStringArray(strategyStr, STRATEGY_LIST) { diff --git a/pkg/compute/models/secgrouprules.go b/pkg/compute/models/secgrouprules.go index 1a32ef1d5b..d1d8a2bd06 100644 --- a/pkg/compute/models/secgrouprules.go +++ b/pkg/compute/models/secgrouprules.go @@ -134,7 +134,7 @@ func (self *SSecurityGroupRule) BeforeInsert() { func (manager *SSecurityGroupRuleManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerProjId string, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) { defsecgroup, _ := data.GetString("secgroup") if len(defsecgroup) == 0 { - return nil, httperrors.NewInputParameterError("Missing Security Group info") + return nil, httperrors.NewMissingParameterError("secgroup") } secgroup, _ := SecurityGroupManager.FetchByIdOrName(userCred, defsecgroup) if secgroup == nil { diff --git a/pkg/compute/models/secgroups.go b/pkg/compute/models/secgroups.go index b53dd3f62f..5d48265179 100644 --- a/pkg/compute/models/secgroups.go +++ b/pkg/compute/models/secgroups.go @@ -214,7 +214,7 @@ func (self *SSecurityGroup) AllowPerformClone(ctx context.Context, userCred mccl func (self *SSecurityGroup) PerformClone(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { if name, _ := data.GetString("name"); len(name) == 0 { - return nil, httperrors.NewInputParameterError("Missing name params") + return nil, httperrors.NewMissingParameterError("name") } else { sql := SecurityGroupManager.Query() sql = SecurityGroupManager.FilterByName(sql, name) diff --git a/pkg/compute/models/storagecaches.go b/pkg/compute/models/storagecaches.go index 6777f4bc37..35bbc2de5f 100644 --- a/pkg/compute/models/storagecaches.go +++ b/pkg/compute/models/storagecaches.go @@ -376,7 +376,7 @@ func (self *SStoragecache) AllowPerformUncacheImage(ctx context.Context, userCre func (self *SStoragecache) PerformUncacheImage(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { imageStr, _ := data.GetString("image") if len(imageStr) == 0 { - return nil, httperrors.NewInputParameterError("missing image id or name") + return nil, httperrors.NewMissingParameterError("image") } isForce := jsonutils.QueryBoolean(data, "is_force", false) diff --git a/pkg/compute/models/vpcs.go b/pkg/compute/models/vpcs.go index 982277493c..38ee08fbfc 100644 --- a/pkg/compute/models/vpcs.go +++ b/pkg/compute/models/vpcs.go @@ -391,19 +391,16 @@ func (manager *SVpcManager) InitializeData() error { func (manager *SVpcManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerProjId string, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) { regionId, err := data.GetString("cloudregion_id") if err != nil { - return nil, httperrors.NewInputParameterError("No cloudregion_id") + return nil, httperrors.NewMissingParameterError("cloudregion_id") } region := CloudregionManager.FetchRegionById(regionId) if region == nil { return nil, httperrors.NewInputParameterError("Invalid cloudregion_id") } if region.isManaged() { - managerStr, _ := data.GetString("manager_id") + managerStr := jsonutils.GetAnyString(data, []string{"manager_id", "manager"}) if len(managerStr) == 0 { - managerStr, _ = data.GetString("manager") - if len(managerStr) == 0 { - return nil, httperrors.NewInputParameterError("cloud provider/manager must be provided") - } + return nil, httperrors.NewMissingParameterError("manager_id") } managerObj := CloudproviderManager.FetchCloudproviderByIdOrName(managerStr) if err != nil { diff --git a/pkg/compute/models/wires.go b/pkg/compute/models/wires.go index f65f6803a6..0b71539e68 100644 --- a/pkg/compute/models/wires.go +++ b/pkg/compute/models/wires.go @@ -78,7 +78,7 @@ func (manager *SWireManager) ValidateCreateData(ctx context.Context, userCred mc vpcStr := jsonutils.GetAnyString(data, []string{"vpc", "vpc_id"}) if len(vpcStr) == 0 { - return nil, httperrors.NewInternalServerError("missing vpc") + return nil, httperrors.NewMissingParameterError("vpc_id") } if len(vpcStr) > 0 { diff --git a/pkg/hostman/guesthandlers/guesthandler.go b/pkg/hostman/guesthandlers/guesthandler.go index 50760596c0..a2e5cc3aad 100644 --- a/pkg/hostman/guesthandlers/guesthandler.go +++ b/pkg/hostman/guesthandlers/guesthandler.go @@ -255,7 +255,7 @@ func guestDestPrepareMigrate(ctx context.Context, sid string, body jsonutils.JSO } else { targetStorageId, _ := disks[0].GetString("target_storage_id") if len(targetStorageId) == 0 { - return nil, httperrors.NewInputParameterError("Disk desc missing target storage id") + return nil, httperrors.NewMissingParameterError("target_storage_id") } params.TargetStorageId = targetStorageId } diff --git a/pkg/httperrors/errors.go b/pkg/httperrors/errors.go index d3ffd49bb7..854c3f634f 100644 --- a/pkg/httperrors/errors.go +++ b/pkg/httperrors/errors.go @@ -3,6 +3,7 @@ package httperrors import ( "bytes" "fmt" + "yunion.io/x/onecloud/pkg/util/httputils" ) diff --git a/pkg/image/models/images.go b/pkg/image/models/images.go index 4dcb92c994..baf1e82b6b 100644 --- a/pkg/image/models/images.go +++ b/pkg/image/models/images.go @@ -1091,7 +1091,7 @@ func (self *SImage) AllowPerformUpdateTorrentStatus(ctx context.Context, userCre func (self *SImage) PerformUpdateTorrentStatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { formatStr, _ := query.GetString("format") if len(formatStr) == 0 { - return nil, httperrors.NewInputParameterError("missing parameter format") + return nil, httperrors.NewMissingParameterError("format") } subimg := ImageSubformatManager.FetchSubImage(self.Id, formatStr) if subimg == nil { diff --git a/pkg/util/aliyun/storagecache.go b/pkg/util/aliyun/storagecache.go index 4be1250805..ef5a6c8d12 100644 --- a/pkg/util/aliyun/storagecache.go +++ b/pkg/util/aliyun/storagecache.go @@ -14,7 +14,6 @@ import ( "yunion.io/x/onecloud/pkg/cloudprovider" "yunion.io/x/onecloud/pkg/compute/options" - "yunion.io/x/onecloud/pkg/httperrors" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/auth" "yunion.io/x/onecloud/pkg/mcclient/modules" @@ -336,7 +335,7 @@ func (self *SStoragecache) downloadImage(userCred mcclient.TokenCredential, imag } else if imageList, err := bucket.ListObjects(oss.Prefix(fmt.Sprintf("%sexport", strings.Replace(extId, "-", "", -1)))); err != nil { return nil, err } else if len(imageList.Objects) != 1 { - return nil, httperrors.NewResourceNotFoundError("exported image not find") + return nil, fmt.Errorf("exported image not find") } else if err := bucket.DownloadFile(imageList.Objects[0].Key, tmpImageFile.Name(), 12*1024*1024, oss.Routines(3), oss.Progress(&OssProgressListener{})); err != nil { return nil, err } else {