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?

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

It's for errors in general, including libuv-based errors (which is where ECONNREFUSED comes from).
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
Any of the libuv errors that mention the net module and/or TCP are relevant for http/https.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.