forked from TrueCloudLab/frostfs-s3-gw
[#125] Updated error handling
Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
parent
e11b1b76ba
commit
e78543adf3
4 changed files with 13 additions and 13 deletions
|
@ -3,14 +3,13 @@ package handler
|
|||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"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/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
const sizeToDetectType = 512
|
||||
|
@ -125,13 +124,8 @@ func (h *handler) HeadBucketHandler(w http.ResponseWriter, r *http.Request) {
|
|||
zap.Error(err))
|
||||
|
||||
code := http.StatusBadRequest
|
||||
if st, ok := status.FromError(err); ok && st != nil {
|
||||
switch st.Code() { //nolint:exhaustive // we have default value set above
|
||||
case codes.NotFound:
|
||||
code = http.StatusNotFound
|
||||
case codes.PermissionDenied:
|
||||
code = http.StatusForbidden
|
||||
}
|
||||
if errors.Is(err, layer.ErrBucketNotFound) {
|
||||
code = http.StatusNotFound
|
||||
}
|
||||
|
||||
api.WriteResponse(w, code, nil, api.MimeNone)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue