Need clarification regarding the Node API

behrangsa

Posted on
Aug 20 2015

Hi,

In your Node JS API, you have this sample code:

var d = require('domain').create();
d.on('error', function(err){
  var killtimer = setTimeout(function() {
    process.exit(1);
  }, 5000);

  killtimer.unref();

  raygunClient.send(err);
  process.exit();
});

d.run(function(){
  var err = new Error('help!');
  throw err;
});

What's the purpose of the killtimer? When it is unrefed it won't block termination of the program, so the process.exit() after raygunClient.send(err) will terminate the program before the killtimer has a chance to be fired.

Or am I miss interpreting something here?

Thanks, Behrang


Callum

Posted on
Aug 28 2015

Apologies for the delay on this one - you've stumbled across some out-of-date documentation which I am updating now. The current canonical use of domains in Node is documented at https://raygun.io/docs/languages/node-js, and there's also a blog post about it at https://raygun.io/blog/2014/03/node-js-error-handling/.

Furthermore, if you're using one of the popular web frameworks we have documentation for these at https://raygun.io/blog/2015/04/nodejs-web-frameworks-and-capturing-errors/. Hope this helps!


Reply