Merge pull request #341 from ywk253100/sync_image

bug fix: when no rows found, return nil not error
This commit is contained in:
Wenkai Yin 2016-06-15 11:42:28 +08:00 committed by GitHub
commit 7393c006c9
2 changed files with 10 additions and 0 deletions

View File

@ -103,6 +103,9 @@ func GetRepPolicy(id int64) (*models.RepPolicy, error) {
var policy models.RepPolicy
if err := o.Raw(sql, id).QueryRow(&policy); err != nil {
if err == orm.ErrNoRows {
return nil, nil
}
return nil, err
}
@ -151,6 +154,9 @@ func GetRepPolicyByName(name string) (*models.RepPolicy, error) {
var policy models.RepPolicy
if err := o.Raw(sql, name).QueryRow(&policy); err != nil {
if err == orm.ErrNoRows {
return nil, nil
}
return nil, err
}

View File

@ -18,6 +18,7 @@ package dao
import (
"fmt"
"github.com/astaxie/beego/orm"
"github.com/vmware/harbor/models"
)
@ -83,6 +84,9 @@ func GetRoleByID(id int) (*models.Role, error) {
var role models.Role
if err := o.Raw(sql, id).QueryRow(&role); err != nil {
if err == orm.ErrNoRows {
return nil, nil
}
return nil, err
}
return &role, nil