Unify error handling in findOneBy() fn
This commit is contained in:
@@ -83,7 +83,9 @@ func (r attachment) findOneBy(namespaceID uint64, field string, value interface{
|
||||
err = rh.FetchOne(r.db(), q, p)
|
||||
)
|
||||
|
||||
if err == nil && p.ID == 0 {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if p.ID == 0 {
|
||||
return nil, ErrAttachmentNotFound
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,9 @@ func (r chart) findOneBy(namespaceID uint64, field string, value interface{}) (*
|
||||
err = rh.FetchOne(r.db(), q, c)
|
||||
)
|
||||
|
||||
if err == nil && c.ID == 0 {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if c.ID == 0 {
|
||||
return nil, ErrChartNotFound
|
||||
}
|
||||
|
||||
|
||||
@@ -102,10 +102,10 @@ func (r module) findOneBy(namespaceID uint64, field string, value interface{}) (
|
||||
err = rh.FetchOne(r.db(), q, m)
|
||||
)
|
||||
|
||||
if m.ID == 0 {
|
||||
return nil, ErrModuleNotFound
|
||||
} else if err != nil {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if m.ID == 0 {
|
||||
return nil, ErrModuleNotFound
|
||||
}
|
||||
|
||||
return m, nil
|
||||
|
||||
@@ -88,7 +88,9 @@ func (r *namespace) findOneBy(field string, value interface{}) (*types.Namespace
|
||||
err = rh.FetchOne(r.db(), q, ns)
|
||||
)
|
||||
|
||||
if err == nil && ns.ID == 0 {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if ns.ID == 0 {
|
||||
return nil, ErrNamespaceNotFound
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ func (r page) columns() []string {
|
||||
|
||||
func (r page) query() squirrel.SelectBuilder {
|
||||
return squirrel.
|
||||
Select().
|
||||
Select(r.columns()...).
|
||||
From(r.table()).
|
||||
Where("deleted_at IS NULL")
|
||||
}
|
||||
@@ -99,7 +99,9 @@ func (r page) findOneBy(namespaceID uint64, field string, value interface{}) (*t
|
||||
err = rh.FetchOne(r.db(), q, p)
|
||||
)
|
||||
|
||||
if err == nil && p.ID == 0 {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if p.ID == 0 {
|
||||
return nil, ErrPageNotFound
|
||||
}
|
||||
|
||||
|
||||
@@ -96,7 +96,9 @@ func (r record) findOneBy(namespaceID uint64, field string, value interface{}) (
|
||||
err = rh.FetchOne(r.db(), q, rec)
|
||||
)
|
||||
|
||||
if err == nil && rec.ID == 0 {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if rec.ID == 0 {
|
||||
return nil, ErrRecordNotFound
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user