Let's say the client sends an ill-formatted request {a:1}
for the service example_interfaces/srv/AddTwoInts
(which requires two properties in the request), in the callback of
createService
:
node.createService('example_interfaces/srv/AddTwoInts', 'add_two_ints', (request, response) => {
console.log(`Incoming request: ${typeof request}`, request);
let result = response.template;
result.sum = request.a + request.b;
console.log(`Sending response: ${typeof result}`, result, '\n--');
response.send(result);
});
We get this output:
Incoming request: object { a: 69, b: 0 }
Sending response: object { sum: 69 }
--
Undefined property request.b
is converted to 0 and doesn't throw an Error. If you print the type of request.b, it's number
.