[#149] Removed grpc errors

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2021-07-12 15:04:27 +03:00
parent 57e2b70614
commit 63652d213c
3 changed files with 12 additions and 24 deletions

View file

@ -8,7 +8,6 @@ import (
"github.com/nspcc-dev/neofs-s3-gw/api"
"github.com/nspcc-dev/neofs-s3-gw/api/layer"
"go.uber.org/zap"
"google.golang.org/grpc/status"
)
// DeleteObjectsRequest - xml carrying the object key names which needs to be deleted.
@ -122,11 +121,6 @@ func (h *handler) DeleteMultipleObjectsHandler(w http.ResponseWriter, r *http.Re
code := "BadRequest"
desc := err.Error()
if st, ok := status.FromError(err.Err); ok && st != nil {
desc = st.Message()
code = st.Code().String()
}
response.Errors = append(response.Errors, DeleteError{
Code: code,
Message: desc,

View file

@ -19,8 +19,6 @@ import (
"github.com/nspcc-dev/neofs-s3-gw/creds/accessbox"
"github.com/nspcc-dev/neofs-sdk-go/pkg/pool"
"go.uber.org/zap"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
type (
@ -123,10 +121,6 @@ type (
)
var (
// ErrObjectExists is returned on attempts to create already existing object.
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")
// ErrBucketNotFound is returned on attempts to get not existing bucket.
@ -257,11 +251,7 @@ func (n *layer) checkObject(ctx context.Context, cid *cid.ID, filename string) e
var err error
if _, err = n.objectFindID(ctx, &findParams{cid: cid, val: filename}); err == nil {
return ErrObjectExists
} else if state, ok := status.FromError(err); !ok || state == nil {
return err
} else if state.Code() == codes.NotFound {
return ErrObjectNotExists
return new(api.ObjectAlreadyExists)
}
return err

View file

@ -81,7 +81,7 @@ func (n *layer) objectFindID(ctx context.Context, p *findParams) (*object.ID, er
if result, err := n.objectSearch(ctx, p); err != nil {
return nil, err
} else if ln := len(result); ln == 0 {
return nil, &api.ObjectNotFound{Bucket: p.cid.String(), Object: p.val}
return nil, api.GetAPIError(api.ErrNoSuchKey)
} else if ln == 1 {
return result[0], nil
}
@ -123,12 +123,16 @@ func (n *layer) objectPut(ctx context.Context, p *PutObjectParams) (*ObjectInfo,
return nil, err
} else if bkt, err = n.GetBucketInfo(ctx, p.Bucket); err != nil {
return nil, err
} else if err = n.checkObject(ctx, bkt.CID, p.Object); err != nil && err != ErrObjectNotExists {
} else if err = n.checkObject(ctx, bkt.CID, p.Object); err != nil {
var errExist *api.ObjectAlreadyExists
if ok := errors.As(err, &errExist); ok {
errExist.Bucket = p.Bucket
errExist.Object = p.Object
return nil, errExist
}
if !api.IsS3Error(err, api.ErrNoSuchKey) {
return nil, err
} else if err == ErrObjectExists {
return nil, &api.ObjectAlreadyExists{
Bucket: p.Bucket,
Object: p.Object,
}
}