0

@grpc/grpc-js: ^1.3.3 Node.js: v14.17.3

Client.js

client.updateBillingItems(request, function(err, response) {
            if (err) {
                res.send({error:'Server failed to update billing item'});
            }
            else {
                res.send(response);
            }
});

backend.js

PCServiceImpl.prototype.updateBillingItems = function updateBillingItems(call, callback) {
    var billingitems = call.request.billingitems; //Here the request received ( request: { billingitems: [] } ) is empty although data is passed from the client. Hence the susequent code fails to execute.
    console.log('updateBillingItems:', billingitems)
    es_query_obj.es_update_billing_items(billingitems)
    .then( results => {
        console.log('updateBillingItems:', JSON.stringify(results));
            callback(null, results);
    })
    .catch(err => {
        console.error("updateBillingItems: Caught ES exception:", err)
        callback(err)
    });
}  

request: { billingitems: [] } -> billingitems must be an array as below

[{"chargemonth":"2021-12","dateofservice":"2021-12-20","geo":"LA"}]

So whenever updateBillingItems() is called by the client.js, it tries to send the updated data in the form of array to backend service, but the the request received by backend service is empty, not sure why. My code uses proto as well, request and response format are according to the proto definitions, but still this call fails.

  • Please include the relevant protobuf message definitions in your question so that we can see how your request object corresponds with them. – murgatroid99 Jan 06 '22 at 19:43

1 Answers1

0

Turns out grpc-js json -> proto conversion has weird naming convention.

Given the following proto def:

message SomeMsg{
   string some_string_field = 1;
}

The client & server impl will need to reference the field w/ camel case

....
console.log(data.someStringField)
...
udi
  • 3,672
  • 2
  • 12
  • 33