Skip to content

Instantly share code, notes, and snippets.

@mikefrey
Last active December 15, 2015 12:19
Show Gist options
  • Save mikefrey/5259691 to your computer and use it in GitHub Desktop.
Save mikefrey/5259691 to your computer and use it in GitHub Desktop.
New Relic node module swallows on uncaught exceptions. Tested on node.js v0.8.22.
var newrelic = require('newrelic')
var http = require('http')
function handleRequest(req, res) {
console.log('Handling request')
// Swallows the exception on the next line.
// Should throw a runtime error instead since DiesHere is undefined.
var x = DiesHere
res.end()
}
var server = http.createServer(handleRequest.bind(this))
server.listen(1337, function(){
process.nextTick(makeRequest)
})
function makeRequest() {
http.get('http://localhost:1337/', function(res) {
console.log('Response received.')
process.exit(0)
})
}
@jwehrlich
Copy link

If you add something like this it should give you the exit your looking for:

process.on('uncaughtException', function(error){
console.error((new Date).toUTCString() + 'uncaughtException: '+error.message);
console.error(error.stack);
process.exit(1)
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment