question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NodeJS code generator / client doesn't fill result correctly on successful write requests

See original GitHub issue

Hello!

Using the samples from https://github.com/Azure/autorest/tree/master/Samples/petstore/NodeJS to access the petstore API the responses of write (for example addPet / updatePet) requests aren’t processed correct.

For example, the code

var uuid = require('uuid');
var SwaggerPetstore = require('./petstore-generated/swaggerPetstore');

var psClient = new SwaggerPetstore('http://petstore.swagger.io/v2');

var pet = {
    "name": uuid.v4(),
    "category": {
        "id": 2,
        "name": "Cats"
    },
    "photoUrls": [],
    "tags": [],
    "status": "available"
};

psClient.addPet({body: pet}, function (err, result, req, res) {
    console.log('err:  ', err);
    console.log('result:  ', result);
    console.log('req:  ', req);
    console.log('res:  ', res);
});

produces the output:

err:   { [Error: {"id":1458394567226,"category":{"id":2,"name":"Cats"},"name":"3ec431eb-fc36-4d73-851c-b266a0d4efda","photoUrls":[],"tags":[],"status":"available"}]
  statusCode: 200,
  request: 
   { rawResponse: false,
     queryString: {},
     method: 'POST',
     headers: { 'Content-Type': 'application/json; charset=utf-8' },
     url: 'http://petstore.swagger.io/v2/pet',
     body: '{"category":{"id":2,"name":"Cats"},"name":"3ec431eb-fc36-4d73-851c-b266a0d4efda","photoUrls":[],"tags":[],"status":"available"}' },
  response: 
   { body: '{"id":1458394567226,"category":{"id":2,"name":"Cats"},"name":"3ec431eb-fc36-4d73-851c-b266a0d4efda","photoUrls":[],"tags":[],"status":"available"}',
     headers: 
      { date: 'Sat, 19 Mar 2016 16:08:01 GMT',
        'access-control-allow-origin': '*',
        'access-control-allow-methods': 'GET, POST, DELETE, PUT',
        'access-control-allow-headers': 'Content-Type, api_key, Authorization',
        'content-type': 'application/json',
        connection: 'close',
        server: 'Jetty(9.2.9.v20150224)' },
     statusCode: 200 } }
result:   undefined
req:   undefined
res:   undefined

As you can see err.statusCode is 200 and in err.response.body resides the data, that I would expect in the result object.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
aschuacommented, Mar 19, 2016

@amarzavery / @devigned: Thanks for your fast responses and explanation!

2reactions
amarzaverycommented, Mar 19, 2016
Read more comments on GitHub >

github_iconTop Results From Across the Web

Top 10 Most Common Node.js Developer Mistakes
js instances - the ones clients connect to concurrently. Mistake #2: Invoking a Callback More Than Once. JavaScript has relied on callbacks since...
Read more >
Node.js v19.3.0 Documentation
Streams compatibility with async generators and async iterators ... instance might contain old data that needs to be // overwritten using fill(), write(), ......
Read more >
Understanding and implementing rate limiting in Node.js
Explore the concept of rate limiting in Node.js — what it is, how it works, various ways to implement it, and some practical...
Read more >
Rendering HTML Pages as an HTTP Server Response ...
In this article, we will consider the various approaches to rendering an HTML page. We will create a Node.js server using Express.js and ......
Read more >
Express/Node introduction - Learn web development | MDN
Hello Node.js. The following example creates a web server that listens for any kind of HTTP request on the URL http://127.0.0.1:8000/ — when ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found