Skip to content

Commit

Permalink
protovalidate: return gRPC status-compatible error
Browse files Browse the repository at this point in the history
  • Loading branch information
ash2k committed Aug 16, 2024
1 parent 114989e commit 69beab3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion interceptors/protovalidate/protovalidate.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (w *wrappedServerStream) RecvMsg(m interface{}) error {
func validateMsg(m interface{}, validator *protovalidate.Validator, opts *options) error {
msg, ok := m.(proto.Message)
if !ok {
return errors.New("unsupported message type")
return status.Errorf(codes.Internal, "unsupported message type: %T", m)
}
if opts.shouldIgnoreMessage(msg.ProtoReflect().Descriptor().FullName()) {
return nil
Expand Down
4 changes: 2 additions & 2 deletions interceptors/protovalidate/protovalidate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ func TestUnaryServerInterceptor(t *testing.T) {

t.Run("not_protobuf", func(t *testing.T) {
_, err = interceptor(context.Background(), "not protobuf", info, handler)
assert.Error(t, err)
assert.Equal(t, codes.Unknown, status.Code(err))
assert.EqualError(t, err, "rpc error: code = Internal desc = unsupported message type: string")
assert.Equal(t, codes.Internal, status.Code(err))
})

interceptor = protovalidate_middleware.UnaryServerInterceptor(validator,
Expand Down

0 comments on commit 69beab3

Please sign in to comment.