diff --git a/api/handler/put.go b/api/handler/put.go index cae8a8df2..71aa0f44f 100644 --- a/api/handler/put.go +++ b/api/handler/put.go @@ -124,6 +124,7 @@ func (h *handler) CreateBucketHandler(w http.ResponseWriter, r *http.Request) { Description: err.Error(), HTTPStatusCode: http.StatusInternalServerError, }, r.URL) + return } h.log.Info("bucket is created", diff --git a/api/layer/layer.go b/api/layer/layer.go index 6dbd7375f..e40380f5c 100644 --- a/api/layer/layer.go +++ b/api/layer/layer.go @@ -127,6 +127,8 @@ var ( ErrObjectExists = errors.New("object exists") // ErrObjectNotExists is returned on attempts to work with non-existing object. ErrObjectNotExists = errors.New("object not exists") + // ErrBucketAlreadyExists is returned on attempts to create already existing bucket. + ErrBucketAlreadyExists = errors.New("bucket exists") ) const ( @@ -491,7 +493,17 @@ func (n *layer) DeleteObjects(ctx context.Context, bucket string, objects []stri } func (n *layer) CreateBucket(ctx context.Context, p *CreateBucketParams) (*cid.ID, error) { - return n.createContainer(ctx, p) + _, err := n.GetBucketInfo(ctx, p.Name) + if err != nil { + errMsg := err.Error() + if strings.Contains(errMsg, "bucket not found") || + strings.Contains(errMsg, "container not found") { + return n.createContainer(ctx, p) + } + return nil, err + } + + return nil, ErrBucketAlreadyExists } func (n *layer) DeleteBucket(ctx context.Context, p *DeleteBucketParams) error {