Skip to content

How to catch ECONNRESET? #705

Closed
Closed
@xl-yang

Description

@xl-yang
  • Node.js Version: 7.10
  • OS: win32
  • Scope (install, code, runtime, meta, other?): code
  • Module (and version) (if relevant): https

I use https.request to read from server, and the response is fine. But after several minutes, ECONNRESET error crash the application. My question is, besides process.on('uncaughtException') (not recommended by Nodejs), is there a proper way to catch and handle ECONNRESET for https.request?

{ Error: read ECONNRESET at exports._errnoException (util.js:1050:11) at TCP.onread (net.js:582:26) code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' }

Below is my code.
` var options = {
method: 'GET',
hostname: hostname,
path: url,
auth: username + ':' + password,
ca: [fs.readFileSync(path.resolve(__dirname, '../common/cer.cer'))],
}

const req = https.request(options, function (res) {

  res.on('data', (resdata) => {
    console.log('data');
  });

  res.on('end', () => {
    console.log('end');
  });
})

req.on('error', (e) => {
  console.log(e);
});

req.end();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions