diff --git a/go.mod b/go.mod index 80ed0e6..ed473cb 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/fasthttp/router v1.0.2 github.com/nspcc-dev/neofs-api-go v0.7.1 github.com/nspcc-dev/neofs-crypto v0.3.0 + github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.5.1 github.com/prometheus/common v0.9.1 github.com/spf13/pflag v1.0.5 diff --git a/receive.go b/receive.go index de2d148..7f09ff4 100644 --- a/receive.go +++ b/receive.go @@ -6,16 +6,17 @@ import ( "net/http" "path" "strconv" - "strings" "time" - "github.com/nspcc-dev/neofs-api-go/container" "github.com/nspcc-dev/neofs-api-go/object" "github.com/nspcc-dev/neofs-api-go/refs" "github.com/nspcc-dev/neofs-api-go/service" + "github.com/pkg/errors" "github.com/valyala/fasthttp" "go.uber.org/zap" "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" ) func (a *app) receiveFile(c *fasthttp.RequestCtx) { @@ -91,14 +92,20 @@ func (a *app) receiveFile(c *fasthttp.RequestCtx) { zap.Stringer("elapsed", time.Since(start)), zap.Error(err)) - switch { - case strings.Contains(err.Error(), object.ErrNotFound.Error()), - strings.Contains(err.Error(), container.ErrNotFound.Error()): - c.Error("object not found", fasthttp.StatusNotFound) - default: - c.Error("could not receive object", fasthttp.StatusBadRequest) + var ( + msg = errors.Wrap(err, "could not receive object").Error() + code = fasthttp.StatusBadRequest + ) + + if st, ok := status.FromError(errors.Cause(err)); ok && st != nil { + if st.Code() == codes.NotFound { + code = fasthttp.StatusNotFound + } + + msg = st.Message() } + c.Error(msg, code) return } }