Return proper error codes, e.g. when providing an empty query

This commit is contained in:
André Duffeck
2022-07-04 16:35:44 +02:00
parent 25ca4150b0
commit 57c4f056ef
2 changed files with 9 additions and 2 deletions
@@ -67,7 +67,7 @@ func New(gwClient gateway.GatewayAPIClient, indexClient search.IndexClient, mach
func (p *Provider) Search(ctx context.Context, req *searchsvc.SearchRequest) (*searchsvc.SearchResponse, error) {
if req.Query == "" {
return nil, errtypes.PreconditionFailed("empty query provided")
return nil, errtypes.BadRequest("empty query provided")
}
p.logger.Debug().Str("query", req.Query).Msg("performing a search")
+8 -1
View File
@@ -7,10 +7,12 @@ import (
"github.com/blevesearch/bleve/v2"
revactx "github.com/cs3org/reva/v2/pkg/ctx"
"github.com/cs3org/reva/v2/pkg/errtypes"
"github.com/cs3org/reva/v2/pkg/events"
"github.com/cs3org/reva/v2/pkg/events/server"
"github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool"
"github.com/go-micro/plugins/v4/events/natsjs"
merrors "go-micro.dev/v4/errors"
"go-micro.dev/v4/metadata"
grpcmetadata "google.golang.org/grpc/metadata"
@@ -95,7 +97,12 @@ func (s Service) Search(ctx context.Context, in *searchsvc.SearchRequest, out *s
Query: in.Query,
})
if err != nil {
return err
switch err.(type) {
case errtypes.BadRequest:
return merrors.BadRequest(s.id, err.Error())
default:
return merrors.InternalServerError(s.id, err.Error())
}
}
out.Matches = res.Matches