Skip to content

Commit 4b7ea58

Browse files
authored
fix(controlplane): handle org update duplicates (#529)
Signed-off-by: Miguel Martinez Trivino <[email protected]>
1 parent ae2e814 commit 4b7ea58

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

app/controlplane/internal/biz/organization.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ func (uc *OrganizationUseCase) Update(ctx context.Context, userID, orgID string,
157157
// Perform the update
158158
org, err := uc.orgRepo.Update(ctx, orgUUID, name)
159159
if err != nil {
160+
if errors.Is(err, ErrAlreadyExists) {
161+
return nil, NewErrValidationStr("an organization with that name already exists")
162+
}
163+
160164
return nil, fmt.Errorf("failed to update organization: %w", err)
161165
} else if org == nil {
162166
return nil, NewErrNotFound("organization")

app/controlplane/internal/data/organization.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ func (r *OrganizationRepo) Update(ctx context.Context, id uuid.UUID, name *strin
7070
}
7171

7272
org, err := req.Save(ctx)
73-
if err != nil {
73+
if err != nil && ent.IsConstraintError(err) {
74+
return nil, biz.ErrAlreadyExists
75+
} else if err != nil {
7476
return nil, fmt.Errorf("failed to update organization: %w", err)
7577
}
7678

0 commit comments

Comments
 (0)