0

I have the following protobuf definition:

service MyService {
    rpc ServiceMethod (ServiceMethodRequest) returns (ServiceMethodResponse) {}
}

message ServiceMethodRequest{
    string requestParam = 1;
}
message ServiceMethodResponse{
    Error error = 1;
    SomeObjectList data = 2;
}
message Error{
    string code = 1;
    string errorMessage = 2;
}

message SomeObject {
    string myobject = 1;
}
message SomeObjectList {
    repeated SomeObject myobjects = 1;
}

As you can see I want to return formatted response so my API has some standardized way of responding. I formatted my response like this (this is in JSON format because of readability):

{"error":{"code":"-1","errorMessage":""},"data":{"myobjects":[{"myobject":"some string"},{"myobject":"another string"}]}}

But on the client side I am constantly getting:

{ Error: 2 UNKNOWN: Unknown Error
    at Object.exports.createStatusError (.../node_modules/grpc/src/common.js:91:15)
    at Object.onReceiveStatus (.../node_modules/grpc/src/client_interceptors.js:1204:28)
    at InterceptingListener._callNext (.../node_modules/grpc/src/client_interceptors.js:568:42)
    at InterceptingListener.onReceiveStatus (.../node_modules/grpc/src/client_interceptors.js:618:8)
    at callback (.../node_modules/grpc/src/client_interceptors.js:845:24)
  code: 2,
  metadata: Metadata { _internal_repr: {}, flags: 0 },
  details: 'Unknown Error' }

when I try to console.log response object.

What am I doing wrong? Also, is there any good book on grpc with some examples (C, C#, Java, Python, JavaScript)? Thanks in advance!

M.Vas
  • 1
  • 1
  • 3
  • it *looks* like it should work... forgetting about the specifics here, does a very simply request/response RPC call work? but in general: you **don't** format the response - gRPC does; is the server here talking gRPC? – Marc Gravell Jul 25 '19 at 12:30
  • Yeah, I didn't format the response, I have just sent the object, and here I had just written it in JSON because I thought it would be more readable. Well it worked when I returned just SomeObjectList. – M.Vas Jul 25 '19 at 12:38

1 Answers1

-1

server.js

callback(null, message);
Dharman
  • 30,962
  • 25
  • 85
  • 135