grpc的状态码 https://github.com/grpc/grpc/bl ob/master/doc/statuscodes.md

1. python的异常处理

1. 服务端(server)

  1. context.set_code(grpc.Status.NOT_FOUND)
  2. context.set_details('记录不存在')

2. 客户端(client)

  1. try:
  2. stub.SayHello(Request())
  3. print(rsp.status)
  4. except grpc.RpcError as e:

2. go的异常处理

1. 服务端(server)

  1. st := status.New(codes.InvalidArgument,"invalid username")

2. 客户端(client)

  1. st,ok := status.FromError(err)
  2. if !ok{
  3. //Error was not a status error
  4. }
  5. st.Message()
  6. st.Code()

3. python和go的互相处理