From c73014bc83aee561d4f0d2f9abc2ca64f50dec17 Mon Sep 17 00:00:00 2001 From: Ritek Rounak Date: Tue, 17 Dec 2024 12:58:28 +0000 Subject: [PATCH] fix: [AH-790] Improve error handling for duplicate Artifact Registry | Gitness (#3170) * fix: [AH-790] Improve error handling for duplicate Artifact Registry --- .../app/api/controller/metadata/create_registry.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/registry/app/api/controller/metadata/create_registry.go b/registry/app/api/controller/metadata/create_registry.go index 45dd9515b..a3cdcfb24 100644 --- a/registry/app/api/controller/metadata/create_registry.go +++ b/registry/app/api/controller/metadata/create_registry.go @@ -108,8 +108,14 @@ func (c *APIController) CreateRegistry( ) if err != nil { + if isDuplicateKeyError(err) { + if err2 := c.handleDuplicateRegistryError(ctx, registry); err2 != nil { + return throwCreateRegistry400Error(err2), nil //nolint:nilerr + } + } return throwCreateRegistry400Error(err), nil //nolint:nilerr } + upstreamproxyEntity, err := c.UpstreamProxyStore.Get(ctx, registryID) if err != nil { return throwCreateRegistry400Error(err), nil //nolint:nilerr @@ -134,6 +140,11 @@ func (c *APIController) createVirtualRegistry( } id, err := c.createRegistryWithAudit(ctx, registry, session.Principal, string(parentRef)) if err != nil { + if isDuplicateKeyError(err) { + if err2 := c.handleDuplicateRegistryError(ctx, registry); err2 != nil { + return throwCreateRegistry400Error(err2), nil //nolint:nilerr + } + } return throwCreateRegistry400Error(err), nil } repoEntity, err := c.RegistryRepository.Get(ctx, id) @@ -197,9 +208,6 @@ func (c *APIController) createRegistryWithAudit( ) (int64, error) { id, err := c.RegistryRepository.Create(ctx, registry) if err != nil { - if isDuplicateKeyError(err) { - return -1, c.handleDuplicateRegistryError(ctx, registry) - } return id, err } auditErr := c.AuditService.Log(