0

My Node.js code to make https POST request is,

var req = https.request(options, function(res) {
  var data = '';

  res.on('data', function(chunk) {
    data += chunk;
  });

  res.on('end', function() {
    var response = JSON.parse(data);
    callback(null, response);
  });
}).on('error', function(err) {
  callback(err);
});

req.write(JSON.stringify(requestObj));
req.end();

I want to know what are the different possible errors I can get. For example, when my target server is not up, I am getting the following error,

{
  [Error: connect ECONNREFUSED 127.0 .0 .1: 3000]
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 3000
}

Here the error code is ECONNREFUSED. What are the possible error scenarios and codes for them? Is there a documentation which covers these?

RaR
  • 3,075
  • 3
  • 23
  • 48

1 Answers1

1

The list of errors can be found in the node.js documentation in the Errors section.

mscdex
  • 104,356
  • 15
  • 192
  • 153
  • It's for errors in general, including libuv-based errors (which is where `ECONNREFUSED` comes from). – mscdex Dec 12 '16 at 08:45
  • If I want to know what are the possible error codes I might get for the above scenario, how can I do so? Since the documentation has all possible error codes, most of which is a not possible for the https scenario – RaR Dec 12 '16 at 08:52
  • 1
    Any of the libuv errors that mention the `net` module and/or TCP are relevant for http/https. – mscdex Dec 12 '16 at 08:59