From 95096e31a7cd34265b1412a585bbbbf132c83d80 Mon Sep 17 00:00:00 2001 From: Poorna Krishnamoorthy Date: Fri, 26 Mar 2021 18:58:13 -0700 Subject: [PATCH] Improve error message from SetRemoteTargetHandler (#11909) --- cmd/admin-bucket-handlers.go | 7 ++++++- cmd/bucket-targets.go | 6 +++--- cmd/object-api-errors.go | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/cmd/admin-bucket-handlers.go b/cmd/admin-bucket-handlers.go index e69867155..1990243be 100644 --- a/cmd/admin-bucket-handlers.go +++ b/cmd/admin-bucket-handlers.go @@ -172,7 +172,12 @@ func (a adminAPIHandlers) SetRemoteTargetHandler(w http.ResponseWriter, r *http. } if err = globalBucketTargetSys.SetTarget(ctx, bucket, &target, update); err != nil { - writeErrorResponseJSON(ctx, w, toAPIError(ctx, err), r.URL) + switch err.(type) { + case BucketRemoteConnectionErr: + writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErrWithErr(ErrReplicationRemoteConnectionError, err), r.URL) + default: + writeErrorResponseJSON(ctx, w, toAPIError(ctx, err), r.URL) + } return } targets, err := globalBucketTargetSys.ListBucketTargets(ctx, bucket) diff --git a/cmd/bucket-targets.go b/cmd/bucket-targets.go index 49c4cf2c8..fdc4fbc85 100644 --- a/cmd/bucket-targets.go +++ b/cmd/bucket-targets.go @@ -100,7 +100,7 @@ func (sys *BucketTargetSys) SetTarget(ctx context.Context, bucket string, tgt *m if minio.ToErrorResponse(err).Code == "NoSuchBucket" { return BucketRemoteTargetNotFound{Bucket: tgt.TargetBucket} } - return BucketRemoteConnectionErr{Bucket: tgt.TargetBucket} + return BucketRemoteConnectionErr{Bucket: tgt.TargetBucket, Err: err} } if tgt.Type == madmin.ReplicationService { if !globalIsErasure { @@ -111,7 +111,7 @@ func (sys *BucketTargetSys) SetTarget(ctx context.Context, bucket string, tgt *m } vcfg, err := clnt.GetBucketVersioning(ctx, tgt.TargetBucket) if err != nil { - return BucketRemoteConnectionErr{Bucket: tgt.TargetBucket} + return BucketRemoteConnectionErr{Bucket: tgt.TargetBucket, Err: err} } if vcfg.Status != string(versioning.Enabled) { return BucketRemoteTargetNotVersioned{Bucket: tgt.TargetBucket} @@ -124,7 +124,7 @@ func (sys *BucketTargetSys) SetTarget(ctx context.Context, bucket string, tgt *m if minio.ToErrorResponse(err).Code == "NoSuchBucket" { return BucketRemoteTargetNotFound{Bucket: tgt.TargetBucket} } - return BucketRemoteConnectionErr{Bucket: tgt.TargetBucket} + return BucketRemoteConnectionErr{Bucket: tgt.TargetBucket, Err: err} } if vcfg.Status != string(versioning.Enabled) { return BucketRemoteTargetNotVersioned{Bucket: tgt.TargetBucket} diff --git a/cmd/object-api-errors.go b/cmd/object-api-errors.go index 846fb26cb..02478891a 100644 --- a/cmd/object-api-errors.go +++ b/cmd/object-api-errors.go @@ -440,7 +440,7 @@ func (e BucketRemoteTargetNotFound) Error() string { type BucketRemoteConnectionErr GenericError func (e BucketRemoteConnectionErr) Error() string { - return "Remote service endpoint or target bucket not available: " + e.Bucket + return fmt.Sprintf("Remote service endpoint or target bucket not available: %s \n\t%s", e.Bucket, e.Err.Error()) } // BucketRemoteAlreadyExists remote already exists for this target type.