[REV] add ErrRecordAlreadyExist for creating version info

This commit is contained in:
GLYASAI 2019-05-06 20:43:58 +08:00
parent f5204be141
commit 222076588b
2 changed files with 9 additions and 4 deletions

View File

@ -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

View File

@ -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