Skip to content

Commit

Permalink
use FromError
Browse files Browse the repository at this point in the history
Signed-off-by: Kosuke Morimoto <[email protected]>
  • Loading branch information
kmrmt committed Oct 3, 2024
1 parent da0ac80 commit cb3a9a2
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions pkg/gateway/filter/handler/grpc/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1448,10 +1448,13 @@ func (s *server) Search(
}
res, err = s.gateway.Search(ctx, req, s.copts...)
if err != nil {
st, msg, err := status.ParseError(err, codes.Internal, "failed to parse "+vald.SearchRPCName+" gRPC error response")
st, ok := status.FromError(err)
if !ok || st == nil {
st = status.New(codes.Internal, "failed to convert "+vald.SearchRPCName+" gRPC error response")
}
if span != nil {
span.RecordError(err)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...)
span.SetStatus(trace.StatusError, err.Error())
}
return nil, err
Expand Down Expand Up @@ -1531,10 +1534,13 @@ func (s *server) SearchByID(
}()
res, err = s.gateway.SearchByID(ctx, req, s.copts...)
if err != nil {
st, msg, err := status.ParseError(err, codes.Internal, "failed to parse "+vald.SearchByIDRPCName+" gRPC error response")
st, ok := status.FromError(err)
if !ok || st == nil {
st = status.New(codes.Internal, "failed to convert "+vald.SearchByIDRPCName+" gRPC error response")
}
if span != nil {
span.RecordError(err)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...)
span.SetStatus(trace.StatusError, err.Error())
}
return nil, err
Expand Down Expand Up @@ -2196,11 +2202,13 @@ func (s *server) StreamLinearSearchByID(
}, nil
})
if err != nil {
st, msg, err := status.ParseError(err, codes.Internal,
"failed to parse "+vald.StreamLinearSearchRPCName+" gRPC error response")
st, ok := status.FromError(err)
if !ok || st == nil {
st = status.New(codes.Internal, "failed to convert "+vald.StreamLinearSearchRPCName+" gRPC error response")
}
if span != nil {
span.RecordError(err)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...)
span.SetStatus(trace.StatusError, err.Error())
}
log.Error(err)
Expand Down Expand Up @@ -3056,10 +3064,13 @@ func (s *server) StreamUpsert(stream vald.Upsert_StreamUpsertServer) (err error)
}, nil
})
if err != nil {
st, msg, err := status.ParseError(err, codes.Internal, "failed to parse "+vald.StreamUpsertRPCName+" gRPC error response")
st, ok := status.FromError(err)
if !ok || st == nil {
st = status.New(codes.Internal, "failed to parse "+vald.StreamUpsertRPCName+" gRPC error response")
}
if span != nil {
span.RecordError(err)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...)
span.SetStatus(trace.StatusError, err.Error())
}
log.Error(err)
Expand Down Expand Up @@ -3223,10 +3234,13 @@ func (s *server) StreamRemove(stream vald.Remove_StreamRemoveServer) (err error)
}, nil
})
if err != nil {
st, msg, err := status.ParseError(err, codes.Internal, "failed to parse "+vald.StreamRemoveRPCName+" gRPC error response")
st, ok := status.FromError(err)
if !ok || st == nil {
st = status.New(codes.Internal, "failed to parse "+vald.StreamRemoveRPCName+" gRPC error response")
}
if span != nil {
span.RecordError(err)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...)
span.SetStatus(trace.StatusError, err.Error())
}
log.Error(err)
Expand Down

0 comments on commit cb3a9a2

Please sign in to comment.