From c1f3110dcc1ff0b742de1857d5ea99c96a79c06e Mon Sep 17 00:00:00 2001 From: Roman Loginov Date: Mon, 16 Dec 2024 10:49:39 +0300 Subject: [PATCH] [#584] Return BucketAlreadyExists when global domain taken A situation may occur when the global domain is already occupied when creating the container. The error comes from the nns smart contract. This error actually means that the bucket has already been created. Signed-off-by: Roman Loginov --- api/errors/errors.go | 4 ++++ api/layer/frostfs/frostfs.go | 3 +++ internal/frostfs/frostfs.go | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/api/errors/errors.go b/api/errors/errors.go index 775add3..7ce7c5f 100644 --- a/api/errors/errors.go +++ b/api/errors/errors.go @@ -1822,6 +1822,10 @@ func TransformToS3Error(err error) error { return GetAPIError(ErrGatewayTimeout) } + if errors.Is(err, frostfs.ErrGlobalDomainIsAlreadyTaken) { + return GetAPIError(ErrBucketAlreadyExists) + } + return GetAPIError(ErrInternalError) } diff --git a/api/layer/frostfs/frostfs.go b/api/layer/frostfs/frostfs.go index f813d0b..847ebd3 100644 --- a/api/layer/frostfs/frostfs.go +++ b/api/layer/frostfs/frostfs.go @@ -233,6 +233,9 @@ var ( // ErrGatewayTimeout is returned from FrostFS in case of timeout, deadline exceeded etc. ErrGatewayTimeout = errors.New("gateway timeout") + + // ErrGlobalDomainIsAlreadyTaken is returned from FrostFS in case of global domain is already taken. + ErrGlobalDomainIsAlreadyTaken = errors.New("global domain is already taken") ) // FrostFS represents virtual connection to FrostFS network. diff --git a/internal/frostfs/frostfs.go b/internal/frostfs/frostfs.go index f89b94b..7298d97 100644 --- a/internal/frostfs/frostfs.go +++ b/internal/frostfs/frostfs.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "strconv" + "strings" "time" "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer/frostfs" @@ -477,6 +478,10 @@ func handleObjectError(msg string, err error) error { return fmt.Errorf("%s: %w: %s", msg, frostfs.ErrGatewayTimeout, err.Error()) } + if strings.Contains(err.Error(), "global domain is already taken") { + return fmt.Errorf("%s: %w: %s", msg, frostfs.ErrGlobalDomainIsAlreadyTaken, err.Error()) + } + return fmt.Errorf("%s: %w", msg, err) }