Skip to content

Instantly share code, notes, and snippets.

@euroelessar
Created May 16, 2018 01:32
Show Gist options
  • Save euroelessar/dde1d70cf8e8fe8dd27a81d6b2b9025f to your computer and use it in GitHub Desktop.
Save euroelessar/dde1d70cf8e8fe8dd27a81d6b2b9025f to your computer and use it in GitHub Desktop.
// Status without details results to non-utf-8 string followed by percent-encoding.
func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) {
grpcStatus := status.New(codes.InvalidArgument, string([]byte{0xff, 0xfe, 0xfd}))
return nil, grpcStatus.Err()
}
// Adding detail to status results to panic.
func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) {
grpcStatus := status.New(codes.InvalidArgument, string([]byte{0xff, 0xfe, 0xfd}))
grpcStatus, err := grpcStatus.WithDetails(&pb.HelloRequest{})
if err != nil {
return nil, err
}
return nil, grpcStatus.Err()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment