forked from TrueCloudLab/frostfs-s3-gw
parent
63652d213c
commit
28974474f2
5 changed files with 268 additions and 34 deletions
270
api/errors.go
270
api/errors.go
File diff suppressed because it is too large
Load diff
|
@ -2,7 +2,6 @@ package handler
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
|
@ -43,10 +42,6 @@ func (h *handler) HeadObjectHandler(w http.ResponseWriter, r *http.Request) {
|
|||
zap.String("object_name", obj),
|
||||
zap.Error(err))
|
||||
|
||||
var genErr *api.ObjectNotFound
|
||||
if ok := errors.As(err, &genErr); ok {
|
||||
err = api.GetAPIError(api.ErrNoSuchKey)
|
||||
}
|
||||
api.WriteErrorResponse(r.Context(), w, err, r.URL)
|
||||
return
|
||||
}
|
||||
|
@ -87,13 +82,7 @@ func (h *handler) HeadBucketHandler(w http.ResponseWriter, r *http.Request) {
|
|||
zap.String("bucket_name", bkt),
|
||||
zap.Error(err))
|
||||
|
||||
code := http.StatusBadRequest
|
||||
if errors.Is(err, layer.ErrBucketNotFound) {
|
||||
code = http.StatusNotFound
|
||||
}
|
||||
|
||||
api.WriteResponse(w, code, nil, api.MimeNone)
|
||||
|
||||
api.WriteErrorResponse(r.Context(), w, err, r.URL)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ func (n *layer) containerInfo(ctx context.Context, cid *cid.ID) (*BucketInfo, er
|
|||
zap.Error(err))
|
||||
|
||||
if strings.Contains(err.Error(), "container not found") {
|
||||
return nil, ErrBucketNotFound
|
||||
return nil, api.GetAPIError(api.ErrNoSuchBucket)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package layer
|
|||
import (
|
||||
"context"
|
||||
"crypto/ecdsa"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/url"
|
||||
|
@ -120,13 +119,6 @@ type (
|
|||
}
|
||||
)
|
||||
|
||||
var (
|
||||
// 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.
|
||||
ErrBucketNotFound = errors.New("bucket not found")
|
||||
)
|
||||
|
||||
const (
|
||||
unversionedObjectVersionID = "null"
|
||||
)
|
||||
|
@ -192,7 +184,7 @@ func (n *layer) GetBucketInfo(ctx context.Context, name string) (*BucketInfo, er
|
|||
}
|
||||
}
|
||||
|
||||
return nil, ErrBucketNotFound
|
||||
return nil, api.GetAPIError(api.ErrNoSuchBucket)
|
||||
}
|
||||
|
||||
return n.containerInfo(ctx, containerID)
|
||||
|
@ -368,13 +360,13 @@ func (n *layer) DeleteObjects(ctx context.Context, bucket string, objects []stri
|
|||
func (n *layer) CreateBucket(ctx context.Context, p *CreateBucketParams) (*cid.ID, error) {
|
||||
_, err := n.GetBucketInfo(ctx, p.Name)
|
||||
if err != nil {
|
||||
if errors.Is(err, ErrBucketNotFound) {
|
||||
if api.IsS3Error(err, api.ErrNoSuchBucket) {
|
||||
return n.createContainer(ctx, p)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return nil, ErrBucketAlreadyExists
|
||||
return nil, api.GetAPIError(api.ErrBucketAlreadyExists)
|
||||
}
|
||||
|
||||
func (n *layer) DeleteBucket(ctx context.Context, p *DeleteBucketParams) error {
|
||||
|
|
|
@ -38,6 +38,7 @@ type (
|
|||
|
||||
// Error structure represents API error.
|
||||
Error struct {
|
||||
ErrCode ErrorCode
|
||||
Code string
|
||||
Description string
|
||||
HTTPStatusCode int
|
||||
|
|
Loading…
Reference in a new issue