Skip to content
This repository has been archived by the owner on Dec 4, 2018. It is now read-only.

Cawllec/fix shouldnt notify logging #113

Merged
merged 9 commits into from
Sep 1, 2017
27 changes: 26 additions & 1 deletion lib/bugsnag.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,31 @@ var domain = require("domain"),
// Ensure we get all stack frames from thrown errors.
Error.stackTraceLimit = Infinity;

// Will ensure errors still logged if shouldNotify is false
function autoNotifyCallback(notifiedError, uncaughtError) {
if (!uncaughtError) {
uncaughtError = notifiedError.domain;
}
return function(error) {
if (error) {
Configuration.logger.error("Bugsnag: error notifying bugsnag.com - " + error);
var errorMsg = [];
if (Bugsnag.shouldNotify()) {
errorMsg.push("An error occurred notifying bugsnag.com")
errorMsg.push("");
errorMsg.push(error.stack);
} else {
if (!Configuration.apiKey) {
errorMsg.push("apiKey not being set prevents the following error from being sent to Bugsnag.");
errorMsg.push("https://docs.bugsnag.com/platforms/nodejs/other/#basic-configuration");
} else {
errorMsg.push("configuration options prevent the following error from being sent to Bugsnag.");
errorMsg.push("https://docs.bugsnag.com/platforms/nodejs/other/configuration-options/#notifyreleasestages");
}
errorMsg.push("");
errorMsg.push(notifiedError.stack);
}
errorMsg.push("");
Configuration.logger.error(errorMsg.join('\n'));
}
if (Configuration.onUncaughtError && uncaughtError) {
return Configuration.onUncaughtError(notifiedError);
Expand Down Expand Up @@ -68,6 +86,13 @@ Bugsnag.register = function(apiKey, options) {
Bugsnag.configure = function(options) {
Configuration.configure(options);

// Warns if the apiKey or release stages will prevent Bugsnag.notify working
if (!Bugsnag.shouldNotify()) {
Configuration.logger.warn(Configuration.apiKey ?
"Current release stage not permitted to send events to Bugsnag." :
"Bugsnag has not been configured with an api key!");
}

// If we should auto notify we also configure the uncaught exception handler, we can't do this
// by default as it changes the way the app response by removing the default handler.
if (Configuration.autoNotifyUncaught && !unCaughtErrorHandlerAdded) {
Expand Down