diff --git a/api/controller/service_action.go b/api/controller/service_action.go index 0e5b06135..decd145f6 100644 --- a/api/controller/service_action.go +++ b/api/controller/service_action.go @@ -20,6 +20,7 @@ package controller import ( "fmt" + "github.com/goodrain/rainbond/db/errors" "io/ioutil" "net/http" "os" @@ -38,7 +39,7 @@ import ( "github.com/goodrain/rainbond/worker/discover/model" "github.com/jinzhu/gorm" "github.com/pquerna/ffjson/ffjson" - validator "github.com/thedevsaddam/govalidator" + "github.com/thedevsaddam/govalidator" ) //TIMELAYOUT timelayout @@ -512,6 +513,11 @@ func (t *TenantStruct) BuildService(w http.ResponseWriter, r *http.Request) { } err = db.GetManager().VersionInfoDao().AddModel(&version) if err != nil { + if err == errors.ErrRecordAlreadyExist { + httputil.ReturnError(r, w, 400, + fmt.Sprintf("service id: %s; build version: %s; version already exists", serviceID, build.Body.DeployVersion)) + return + } logrus.Infof("error add version %v ,details %s", version, err.Error()) httputil.ReturnError(r, w, 500, "create service version error.") return diff --git a/db/mysql/dao/version.go b/db/mysql/dao/version.go index ab18f1afa..df8071638 100644 --- a/db/mysql/dao/version.go +++ b/db/mysql/dao/version.go @@ -19,10 +19,9 @@ package dao import ( + "github.com/goodrain/rainbond/db/errors" "github.com/goodrain/rainbond/db/model" - "fmt" - "time" "github.com/jinzhu/gorm" @@ -58,7 +57,7 @@ func (c *VersionInfoDaoImpl) AddModel(mo model.Interface) error { } return nil } - return fmt.Errorf("service %s build version %s is exist", result.ServiceID, result.BuildVersion) + return errors.ErrRecordAlreadyExist } //UpdateModel UpdateModel