Thursday, 16 March 2017

How to return grpc error in nodejs

I want to return grpc error code and description in server-side. I have tried this

function sayHello(call, callback) {
  callback({error: {code: 400, message: "invalid input"});
}

but I got this exception from client

{ Error: Unknown Error
    at /home/thanh/email/node_modules/grpc/src/node/src/client.js:434:17 code: 2, metadata: Metadata { _internal_repr: {} } }

If I don't want to include error field in message definition like this.

message Hello {
  string name = 1;
  string error = 2; // don't want this
}

Then what is the proper way to send grpc error back to client ?



via thanhpk

No comments:

Post a Comment