Node application not catching & sending errors
optikalefx
Posted on
Apr 14 2015
I've followed the various methods here https://raygun.io/blog/2013/04/raygun4node-node-js-provider-now-available/ but when I cause a TypeError, it doesn't get sent. TypeError: Object [object Object] has no method 'whoaThere'
I've even logged that the error is properly caught in console and it is with process.on('uncaughtException' but not with domains.
neither get sent to Raygun though. I'm on Node v0.10.26 on the latest MacOS
Jamie Penney
Posted on
Apr 14 2015
Hi,
So it doesn't work if you manually construct a client and call send(error)
? That indicates there's either a problem with your API key or with your network blocking the send. Can you double check your API key?
If that doesn't work, I'll get you to manually POST an example error to our servers from the same machine. Send an HTTP POST request with the X-ApiKey
header set to your Application's ApiKey, Content-Type
set to application/json
, and the body set to the following:
{
"OccurredOn": "2015-04-13T01:19:59Z" ,
"Details": {
"Error": {
"Message": "Uncaught exception: ReferenceError: Undefined variable: nonexistant",
"StackTrace": [
{
"LineNumber": 3,
"ClassName": "line 3, column undefined",
"FileName": "http://localhost:1484/childscript.js",
"MethodName": "?"
}
]
}
}
}
If that works, I'll probably need to see your Node app's set up.
optikalefx
Posted on
Apr 15 2015
So from the starter code I was first given, it did send the phasers error. But I can't get back to that page to see what that code was, but since then I couldn't get anything to run.
With that said, this is the code I'm using in my app.js file
var raygun = require('raygun');
var raygunClient = new raygun.Client().init({ apiKey: 'mykey' });
var d = require('domain').create();
d.on('error', function(err){
console.log("error thrown");
var killtimer = setTimeout(function() {
console.log("dead");
process.exit(1);
}, 5000);
killtimer.unref();
raygunClient.send(err);
process.exit();
});
d.run(function(){
console.log("run");
var err = new Error('NEW ERROR!');
throw err;
});
And my console says
run
error thrown
But never get's into that timer, and never sends data to raygun. I've tripple checked my API key as well.
Daniel
Posted on
Apr 15 2015
Hey,
Have just had a play with your sample code there - it seems to be exiting before it gets a chance to send the error (The process.exit() at the bottom of the on('error') method).
Here's the sample from the create application screen again, where it exits when the Raygun callback is called.
var d = require('domain').create();
d.on('error', function(err){
raygunClient.send(err, {}, function () {
process.exit();
});
});
d.run(function(){
var err = new Error('phasers offline');
throw err;
});
Cheers,
Daniel
optikalefx
Posted on
Apr 16 2015
Nice, I think this is working now. You should issue a fix to your node docs page with this working code.
Thanks for the help!
Daniel
Posted on
Apr 16 2015
Awesome, glad to hear it's all working!
I updated the docs yesterday - so they now match the sample given when you create an application.
Cheers, Daniel