[#30] Fix not found responses

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2021-07-20 13:40:39 +03:00
parent ce32b26e87
commit 03a3f986ff

View file

@ -18,8 +18,6 @@ import (
"github.com/nspcc-dev/neofs-sdk-go/pkg/pool" "github.com/nspcc-dev/neofs-sdk-go/pkg/pool"
"github.com/valyala/fasthttp" "github.com/valyala/fasthttp"
"go.uber.org/zap" "go.uber.org/zap"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
) )
type ( type (
@ -210,12 +208,13 @@ func (r *request) handleNeoFSErr(err error, start time.Time) {
for unwrap := errors.Unwrap(err); unwrap != nil; unwrap = errors.Unwrap(cause) { for unwrap := errors.Unwrap(err); unwrap != nil; unwrap = errors.Unwrap(cause) {
cause = unwrap cause = unwrap
} }
if st, ok := status.FromError(cause); ok && st != nil {
if st.Code() == codes.NotFound { if strings.Contains(cause.Error(), "not found") ||
code = fasthttp.StatusNotFound strings.Contains(cause.Error(), "can't fetch container info") {
} code = fasthttp.StatusNotFound
msg = st.Message() msg = errObjectNotFound.Error()
} }
r.Error(msg, code) r.Error(msg, code)
} }