diff --git a/src/core/common/utility.go b/src/core/common/utility.go index c8ea35c99..516fa6bbe 100644 --- a/src/core/common/utility.go +++ b/src/core/common/utility.go @@ -466,7 +466,7 @@ func GetConnConfigList() (ConnConfigList, error) { if err != nil { CBLog.Error(err) content := ConnConfigList{} - err := fmt.Errorf("an error occurred while requesting to CB-Spider") + err := fmt.Errorf("Error from CB-Spider: " + err.Error()) return content, err } diff --git a/src/core/mcir/securitygroup.go b/src/core/mcir/securitygroup.go index 8d60037a0..c27158633 100644 --- a/src/core/mcir/securitygroup.go +++ b/src/core/mcir/securitygroup.go @@ -193,27 +193,35 @@ func CreateSecurityGroup(nsId string, u *TbSecurityGroupReq, option string) (TbS if err != nil { common.CBLog.Error(err) - err := fmt.Errorf("Cannot ListResourceId securityGroup") + err := fmt.Errorf("Cannot list vNet Ids for securityGroup") return TbSecurityGroupInfo{}, err } - var content struct { - VNet []TbVNetInfo `json:"vNet"` - } - content.VNet = resourceList.([]TbVNetInfo) // type assertion (interface{} -> array) + if resourceList != nil { + var content struct { + VNet []TbVNetInfo `json:"vNet"` + } + content.VNet = resourceList.([]TbVNetInfo) // type assertion (interface{} -> array) + + if len(resourceList.([]TbVNetInfo)) == 0 { + errString := "There is no " + common.StrVNet + " resource in " + nsId + err := fmt.Errorf(errString) + common.CBLog.Error(err) + return TbSecurityGroupInfo{}, err + } - if len(content.VNet) == 0 { - errString := "There is no " + common.StrVNet + " resource in " + nsId + // Assign random temporal ID to u.VNetId (should be in the same Connection with SG) + for _, r := range content.VNet { + if r.ConnectionName == u.ConnectionName { + u.VNetId = r.Id + } + } + } else { + errString := "nil was returned for vNet list in " + nsId err := fmt.Errorf(errString) common.CBLog.Error(err) return TbSecurityGroupInfo{}, err } - - for _, r := range content.VNet { - if r.ConnectionName == u.ConnectionName { - u.VNetId = r.Id - } - } } vNetInfo := TbVNetInfo{}