Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[server]fix: use proper Error causes

mngshma7f31119fe3d
diff --git a/server/ente/errors.go b/server/ente/errors.go
index aac78f6f73..b629674277 100644
--- a/server/ente/errors.go
+++ b/server/ente/errors.go
@@ -94,6 +94,13 @@ var ErrLockUnavailable = errors.New("could not acquire lock")
// ErrActiveLinkAlreadyExists is thrown when the collection already has active public link
var ErrActiveLinkAlreadyExists = errors.New("Collection already has active public link")
+// ErrCannotModifyAdminStoragLimit is thrown when the admin is modifying their own storage limit
+var ErrCannotModifyAdminStoragLimit = errors.New("Cannot modify admin storage limit")
+
+// ErrFailedReducingStorageLimit is thrown when the admin is setting storage limit lesser than
+// members pre-consumed storage
+var ErrFailedReducingStorageLimit = errors.New("Members Usage is more than potential storage limit")
+
// ErrNotImplemented indicates that the action that we tried to perform is not
// available at this museum instance. e.g. this could be something that is not
// enabled on this particular instance of museum.
diff --git a/server/pkg/controller/family/admin.go b/server/pkg/controller/family/admin.go
index e6bef578c1..228d16f0c4 100644
--- a/server/pkg/controller/family/admin.go
+++ b/server/pkg/controller/family/admin.go
@@ -194,7 +194,7 @@ func (c *Controller) CloseFamily(ctx context.Context, adminID int64) error {
func (c *Controller) ModifyMemberStorage(ctx context.Context, adminID int64, id uuid.UUID, storageLimit *int64) error {
familyAdminID, err := c.UserRepo.GetFamilyAdminID(adminID)
if err != nil {
- return stacktrace.Propagate(err, "Could not get family admin ID")
+ return stacktrace.Propagate(ente.ErrBadRequest, "Could not get family admin ID")
}
member, err := c.FamilyRepo.GetMemberById(ctx, id)
@@ -205,11 +205,11 @@ func (c *Controller) ModifyMemberStorage(ctx context.Context, adminID int64, id
// gets admin subscription in order to get the size of total storage quota
activeSub, err := c.BillingCtrl.GetActiveSubscription(adminID)
if err != nil {
- return stacktrace.Propagate(err, "couldn't get active subscription")
+ return stacktrace.Propagate(ente.ErrNoActiveSubscription, "couldn't get active subscription")
}
if storageLimit != nil && *storageLimit > activeSub.Storage {
- return stacktrace.Propagate(fmt.Errorf("cannot set storage limit"), "potential storage limit is more than subscription storage")
+ return stacktrace.Propagate(ente.ErrStorageLimitExceeded, "potential storage limit is more than subscription storage")
}
// Handle if the admin user tries reducing the storage Limit
@@ -220,11 +220,11 @@ func (c *Controller) ModifyMemberStorage(ctx context.Context, adminID int64, id
}
if adminID == *familyAdminID && member.IsAdmin {
- return stacktrace.Propagate(fmt.Errorf("cannot modify storage"), "cannot modify admin storage limit")
+ return stacktrace.Propagate(ente.ErrCannotModifyAdminStoragLimit, "cannot modify admin storage limit")
}
if memberUsage > *storageLimit {
- return stacktrace.Propagate(fmt.Errorf("storage reduction not allowed"), "Cannot reduce storage, current usage is more.")
+ return stacktrace.Propagate(ente.ErrFailedReducingStorageLimit, "Cannot reduce storage, current usage is more.")
}
if id == member.ID && member.Status == "ACCEPTED" {
@@ -233,7 +233,7 @@ func (c *Controller) ModifyMemberStorage(ctx context.Context, adminID int64, id
return stacktrace.Propagate(err, "Cannot Modify Members Storage")
}
} else {
- return stacktrace.Propagate(fmt.Errorf("could not modify storage"), "user is not a part of family")
+ return stacktrace.Propagate(ente.ErrBadRequest, "user is not a part of family")
}
return nil
}