Skip to content

Undefined properties of requests are converted to 0 in the callback of createService #243

@qiuzhong

Description

@qiuzhong

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions