node.js-domains

How to use Node.js 0.8.x domains with express?

£可爱£侵袭症+ 提交于 2019-12-02 18:13:01
How can I create Express/Connect middleware which wrap each request in its own domain? This set of slides on Speaker Deck gives a succinct overview: Domains in node 0.8 Express middleware code from the slides: var createDomain = require('domain').create; app.use(function(req, res, next) { var domain = createDomain(); domain.on('error', function(err) { // alternative: next(err) res.statusCode = 500; res.end(err.message + '\n'); domain.dispose(); }); domain.enter(); next(); }); UPDATE: The approach described below has been implemented in the connect-domain NodeJS module, which can be used in

Domains not properly catching errors while testing nodeJS in mocha

徘徊边缘 提交于 2019-11-29 15:50:55
问题 When running tests that utilize domains for error handling, Mocha still appears to be throwing an error even if a domain handler inside a library should have caught the error. If I execute the code outside of Mocha, it functions correctly leading me to believe the problem is Mocha. Example: foo.js module.exports = function(done) { var domain = require("domain"); var d = domain.create(); d.on("error", function() { done(); }); d.run(function() { throw new Error("foo"); }); } test.js - Error

Unable to handle exception with node.js domains using express

独自空忆成欢 提交于 2019-11-29 01:29:27
I want to use Node.js Domains to catch exceptions. It is working so far, but there is one place I can't get domains to catch the exception. exception2 in the callback is caught and handled in the domain.on('error') handler, but exception1 is not caught. The odd thing is that when exception1 is thrown, it doesn't shutdown Node like I would expect. Here is my example app: var domain = require('domain'); var request = require('request'); var express = require('express'); var serverDomain = domain.create(); serverDomain.on('error', function(err) { console.log("Server Domain Error: " + err); });

Unable to handle exception with node.js domains using express

大城市里の小女人 提交于 2019-11-27 15:59:03
问题 I want to use Node.js Domains to catch exceptions. It is working so far, but there is one place I can't get domains to catch the exception. exception2 in the callback is caught and handled in the domain.on('error') handler, but exception1 is not caught. The odd thing is that when exception1 is thrown, it doesn't shutdown Node like I would expect. Here is my example app: var domain = require('domain'); var request = require('request'); var express = require('express'); var serverDomain =