-
-
Save kattrali/1ac8dcb209fcd5b5db2e5e16afafae60 to your computer and use it in GitHub Desktop.
demonstration of promises breaking bugsnag requestData. Tested with node v6.9 and v8.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require("express"); | |
const bugsnag = require("bugsnag"); | |
const unhandledRejection = require("unhandled-rejection"); | |
let rejectionEmitter = unhandledRejection({ timeout: 20 }); | |
rejectionEmitter.on("unhandledRejection", (error) => { | |
console.log("Promise....REJECTED!"); | |
bugsnag.notify(error); | |
}); | |
const app = express(); | |
bugsnag.register("SOME-KEY"); | |
app.use(bugsnag.requestHandler); | |
bugsnag.onBeforeNotify((notification) => { | |
console.log("callback request data: " + process.domain._bugsnagOptions); | |
return false; | |
}); | |
// works just fine | |
app.get("/", (req, res, next) => { | |
console.log("GET request data: " + process.domain._bugsnagOptions); | |
}); | |
// fails, but because there's no domain context when the rejection emitter | |
// catches the promise rejection. Regular throws don't have this problem. | |
app.post("/", (req, res, next) => { | |
console.log("POST request data: " + process.domain._bugsnagOptions); | |
new Promise((res, rej) => { | |
rej(new Error("Oh no")); | |
}); | |
}); | |
app.listen(3000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"dependencies": { | |
"bugsnag": "^1.9.1", | |
"express": "^4.15.3", | |
"unhandled-rejection": "^1.0.0" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
POST request data: [object Object] | |
Promise....REJECTED! | |
/Users/delisa/Code/bugsnag/sample-apps/js/node-domain-test/index.js:18 | |
console.log("callback request data: " + process.domain._bugsnagOptions); | |
^ | |
TypeError: Cannot read property '_bugsnagOptions' of undefined | |
at bugsnag.onBeforeNotify (/Users/delisa/Code/bugsnag/sample-apps/js/node-domain-test/index.js:18:57) | |
at Notification.<anonymous> (/Users/delisa/Code/bugsnag/sample-apps/js/node-domain-test/node_modules/bugsnag/lib/notification.js:116:19) | |
at Array.forEach (native) | |
at Notification.deliver (/Users/delisa/Code/bugsnag/sample-apps/js/node-domain-test/node_modules/bugsnag/lib/notification.js:115:41) | |
at Object.Bugsnag.notify (/Users/delisa/Code/bugsnag/sample-apps/js/node-domain-test/node_modules/bugsnag/lib/bugsnag.js:111:22) | |
at process.<anonymous> (/Users/delisa/Code/bugsnag/sample-apps/js/node-domain-test/node_modules/bugsnag/lib/bugsnag.js:75:21) | |
at emitOne (events.js:115:13) | |
at process.emit (events.js:210:7) | |
at process._fatalException (bootstrap_node.js:329:26) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment