forked from TrueCloudLab/frostfs-http-gw
errors: correct handling 404
This commit is contained in:
parent
96e24653f7
commit
12a3801f3d
2 changed files with 16 additions and 8 deletions
1
go.mod
1
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
|
||||
|
|
23
receive.go
23
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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue