aboutsummaryrefslogtreecommitdiff
path: root/item
diff options
context:
space:
mode:
Diffstat (limited to 'item')
-rw-r--r--item/hooks.go5
-rw-r--r--item/validators.go2
2 files changed, 6 insertions, 1 deletions
diff --git a/item/hooks.go b/item/hooks.go
index 5a27114..c7dc498 100644
--- a/item/hooks.go
+++ b/item/hooks.go
@@ -20,6 +20,7 @@ package item
import (
"gorm.io/gorm"
"vidhukant.com/openbills/errors"
+ e "errors"
)
func (i *SavedItem) BeforeSave(tx *gorm.DB) error {
@@ -28,6 +29,10 @@ func (i *SavedItem) BeforeSave(tx *gorm.DB) error {
// also checks if brand actually exists
err = checkBrandOwnership(i.BrandID, i.UserID)
if err != nil {
+ if e.Is(err, errors.ErrBrandNotFound) {
+ // this error has a better error message for this case
+ return errors.ErrBrandNotFound
+ }
return err
}
diff --git a/item/validators.go b/item/validators.go
index e931843..b808ae4 100644
--- a/item/validators.go
+++ b/item/validators.go
@@ -105,7 +105,7 @@ func checkBrandOwnership(brandId, userId uint) error {
// brand doesn't exist
if brand.ID == 0 {
- return errors.ErrBrandNotFound
+ return errors.ErrNotFound
}
// user doesn't own this brand