Comparing version 0.1.0 to 0.1.1
trace = require('tracejs').trace; | ||
http = require('http'); | ||
fs = require('fs'); | ||
path = require('path'); | ||
@@ -9,3 +10,3 @@ var defaultErrorHash = { | ||
name : "Bugsnag Node Notifier", | ||
version : "1.0.0", | ||
version : "", | ||
url : "www.bugsnag.com" | ||
@@ -20,3 +21,3 @@ } | ||
var onUncaughtException = function(err) { | ||
exit(); | ||
exit(1); | ||
} | ||
@@ -29,2 +30,13 @@ | ||
getPackageVersion = function(packageJSON) { | ||
try { | ||
contents = fs.readFileSync(packageJSON, 'UTF-8'); | ||
} catch(e) { | ||
return "unknown"; | ||
} | ||
packageInfo = JSON.parse(contents); | ||
return packageInfo.version; | ||
} | ||
// Send a test notification | ||
exports.testNotification = function() { | ||
@@ -34,2 +46,3 @@ exports.notify(new Error("Test error ")); | ||
// Notify about a caught error | ||
exports.notify = function(error) { | ||
@@ -48,3 +61,3 @@ var stacktrace = trace(error); | ||
errorClass: "Error", | ||
message: stacktrace.first_line, | ||
message: stacktrace.first_line.substr(7), | ||
stacktrace: [] | ||
@@ -69,2 +82,6 @@ }] | ||
if ( contextLambda !== undefined ) { | ||
errorList[0].context = contextLambda(); | ||
} | ||
defaultErrorHash.errors = errorList; | ||
@@ -85,2 +102,3 @@ | ||
var req = http.request(options, function(response) {}); | ||
console.log(payload) | ||
req.write(payload, 'utf8'); | ||
@@ -90,2 +108,3 @@ req.end(); | ||
// Register to process uncaught exceptions properly | ||
exports.register = function(apiKey, options) { | ||
@@ -99,11 +118,14 @@ Error.stackTraceLimit = Infinity; | ||
if ( options.packageJSON !== undefined ) { | ||
populateApplicationVersion(options.packageJSON); | ||
applicationVersion = getPackageVersion(options.packageJSON); | ||
} | ||
if( applicationVersion === undefined || applicationVersion == "unknown" ) { | ||
populateApplicationVersion(__dirname + '/../package.json'); | ||
applicationVersion = getPackageVersion(path.join(__dirname, '../../package.json')); | ||
} | ||
projectDirectory = (options.projectDirectory === undefined ? "" : options.projectDirectory); | ||
projectDirectory = (options.projectDirectory === undefined ? path.join(__dirname, "../..") : options.projectDirectory); | ||
console.log(projectDirectory) | ||
defaultErrorHash.notifier.version = getPackageVersion(path.join(__dirname,'package.json')) | ||
} | ||
// Set a lambda function to detail the context of the call | ||
exports.setContext = function(lambda) { | ||
@@ -113,2 +135,3 @@ contextLambda = lambda | ||
// Set a lambda function to detail the user affected | ||
exports.setUserId = function(lambda) { | ||
@@ -118,2 +141,3 @@ userIdLambda = lambda; | ||
// Set a lambda function to detail what happens once an uncaught exception is processed. Defaults to exit(1) | ||
exports.setUncaughtExceptionHandler = function(lambda) { | ||
@@ -123,15 +147,5 @@ onUncaughtException = lambda; | ||
// Set the application version | ||
exports.setApplicationVersion = function(version) { | ||
applicationVersion = version; | ||
} | ||
populateApplicationVersion = function(packageJSON) { | ||
try { | ||
contents = fs.readFileSync(packageJSON, 'UTF-8'); | ||
} catch(e) { | ||
applicationVersion = "unknown"; | ||
return; | ||
} | ||
packageInfo = JSON.parse(contents); | ||
applicationVersion = packageInfo.version; | ||
} |
{ | ||
"name": "bugsnag", | ||
"description": "Bugsnag notifier for node.js scripts", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"main": "./bugsnag.js", | ||
@@ -6,0 +6,0 @@ "homepage": "http://bugsnag.com", |
4474
122