From 0037951b6e8315d1370a8ba4ec326ffe679e5720 Mon Sep 17 00:00:00 2001 From: poornas Date: Fri, 4 Sep 2020 08:48:38 -0700 Subject: [PATCH] improve error message when remote target missing (#10412) --- cmd/api-errors.go | 8 ++++++++ cmd/bucket-targets.go | 11 ++++++----- cmd/object-api-errors.go | 7 +++++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/cmd/api-errors.go b/cmd/api-errors.go index 937885a29..13a072c3e 100644 --- a/cmd/api-errors.go +++ b/cmd/api-errors.go @@ -109,6 +109,7 @@ const ( ErrReplicationDestinationNotFoundError ErrReplicationDestinationMissingLock ErrReplicationTargetNotFoundError + ErrReplicationRemoteConnectionError ErrBucketRemoteIdenticalToSource ErrBucketRemoteAlreadyExists ErrBucketRemoteArnTypeInvalid @@ -823,6 +824,11 @@ var errorCodes = errorCodeMap{ Description: "The replication target does not exist", HTTPStatusCode: http.StatusNotFound, }, + ErrReplicationRemoteConnectionError: { + Code: "XminioAdminReplicationRemoteConnectionError", + Description: "Remote service endpoint or target bucket not available", + HTTPStatusCode: http.StatusNotFound, + }, ErrBucketRemoteIdenticalToSource: { Code: "XminioAdminRemoteIdenticalToSource", Description: "The remote target cannot be identical to source", @@ -1906,6 +1912,8 @@ func toAPIErrorCode(ctx context.Context, err error) (apiErr APIErrorCode) { apiErr = ErrReplicationDestinationMissingLock case BucketRemoteTargetNotFound: apiErr = ErrReplicationTargetNotFoundError + case BucketRemoteConnectionErr: + apiErr = ErrReplicationRemoteConnectionError case BucketRemoteAlreadyExists: apiErr = ErrBucketRemoteAlreadyExists case BucketRemoteArnTypeInvalid: diff --git a/cmd/bucket-targets.go b/cmd/bucket-targets.go index 2b2eedaea..8c6a01840 100644 --- a/cmd/bucket-targets.go +++ b/cmd/bucket-targets.go @@ -21,6 +21,7 @@ import ( "net/http" "sync" + minio "github.com/minio/minio-go/v7" miniogo "github.com/minio/minio-go/v7" "github.com/minio/minio-go/v7/pkg/credentials" "github.com/minio/minio/pkg/bucket/versioning" @@ -91,13 +92,13 @@ func (sys *BucketTargetSys) SetTarget(ctx context.Context, bucket string, tgt *m } vcfg, err := clnt.GetBucketVersioning(ctx, tgt.TargetBucket) if err != nil { - if isErrBucketNotFound(err) { + if minio.ToErrorResponse(err).Code == "NoSuchBucket" { return BucketRemoteTargetNotFound{Bucket: tgt.TargetBucket} } - if vcfg.Status != string(versioning.Enabled) { - return BucketReplicationTargetNotVersioned{Bucket: tgt.TargetBucket} - } - return err + return BucketRemoteConnectionErr{Bucket: tgt.TargetBucket} + } + if vcfg.Status != string(versioning.Enabled) { + return BucketReplicationTargetNotVersioned{Bucket: tgt.TargetBucket} } } diff --git a/cmd/object-api-errors.go b/cmd/object-api-errors.go index 30b346a38..caeeaa415 100644 --- a/cmd/object-api-errors.go +++ b/cmd/object-api-errors.go @@ -376,6 +376,13 @@ func (e BucketRemoteTargetNotFound) Error() string { return "Remote target not found: " + e.Bucket } +// BucketRemoteConnectionErr remote target connection failure. +type BucketRemoteConnectionErr GenericError + +func (e BucketRemoteConnectionErr) Error() string { + return "Remote service endpoint or target bucket not available: " + e.Bucket +} + // BucketRemoteAlreadyExists remote already exists for this target type. type BucketRemoteAlreadyExists GenericError