mirror of
https://github.com/goharbor/harbor
synced 2024-09-21 00:39:58 +00:00
bug fix: when no rows found, return nil not error
This commit is contained in:
parent
7f31c3901b
commit
96c9e4c202
|
@ -103,6 +103,9 @@ func GetRepPolicy(id int64) (*models.RepPolicy, error) {
|
||||||
var policy models.RepPolicy
|
var policy models.RepPolicy
|
||||||
|
|
||||||
if err := o.Raw(sql, id).QueryRow(&policy); err != nil {
|
if err := o.Raw(sql, id).QueryRow(&policy); err != nil {
|
||||||
|
if err == orm.ErrNoRows {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,6 +154,9 @@ func GetRepPolicyByName(name string) (*models.RepPolicy, error) {
|
||||||
var policy models.RepPolicy
|
var policy models.RepPolicy
|
||||||
|
|
||||||
if err := o.Raw(sql, name).QueryRow(&policy); err != nil {
|
if err := o.Raw(sql, name).QueryRow(&policy); err != nil {
|
||||||
|
if err == orm.ErrNoRows {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ package dao
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/astaxie/beego/orm"
|
||||||
"github.com/vmware/harbor/models"
|
"github.com/vmware/harbor/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -83,6 +84,9 @@ func GetRoleByID(id int) (*models.Role, error) {
|
||||||
|
|
||||||
var role models.Role
|
var role models.Role
|
||||||
if err := o.Raw(sql, id).QueryRow(&role); err != nil {
|
if err := o.Raw(sql, id).QueryRow(&role); err != nil {
|
||||||
|
if err == orm.ErrNoRows {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &role, nil
|
return &role, nil
|
||||||
|
|
Loading…
Reference in New Issue
Block a user