3
0

Unify error handling in findOneBy() fn

This commit is contained in:
Denis Arh
2019-10-17 16:13:14 +02:00
parent c6688db3d0
commit 8f0fc8b58f
6 changed files with 19 additions and 9 deletions
+3 -1
View File
@@ -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
}
+3 -1
View File
@@ -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
}
+3 -3
View File
@@ -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
+3 -1
View File
@@ -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
}
+4 -2
View File
@@ -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
}
+3 -1
View File
@@ -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
}