Skip to content

Commit

Permalink
Revert "Added double-next reporting"
Browse files Browse the repository at this point in the history
This reverts commit 4046ad0.
  • Loading branch information
tj committed Aug 26, 2011
1 parent 9d78e88 commit 81d9f22
Showing 1 changed file with 3 additions and 36 deletions.
39 changes: 3 additions & 36 deletions lib/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ Server.prototype.use = function(route, handle){
Server.prototype.handle = function(req, res, out) {
var writeHead = res.writeHead
, stack = this.stack
, called = []
, removed = ''
, index = 0;

Expand All @@ -145,17 +144,6 @@ Server.prototype.handle = function(req, res, out) {

layer = stack[index++];

// callback used to track
// and report double next()
function callback(err) {
if (~called.indexOf(layer.handle)) {
reportDoubleNext(layer.handle);
} else {
called.push(layer.handle);
next(err);
}
}

// all done
if (!layer) {
// but wait! we have a parent
Expand Down Expand Up @@ -202,12 +190,12 @@ Server.prototype.handle = function(req, res, out) {
var arity = layer.handle.length;
if (err) {
if (arity === 4) {
layer.handle(err, req, res, callback);
layer.handle(err, req, res, next);
} else {
next(err);
}
} else if (arity < 4) {
layer.handle(req, res, callback);
layer.handle(req, res, next);
} else {
next();
}
Expand All @@ -221,25 +209,4 @@ Server.prototype.handle = function(req, res, out) {
}
}
next();
};

/**
* Report that the given `fn` was invoked
* more than once. This _is_ an error, and
* should be fixed in your application, however
* this logic prevents the user from seeing
* how node handles it via more obscure
* errors such as: "Error: Can't set headers after they are sent."
*
* @param {Function} fn
* @api private
*/

function reportDoubleNext(fn) {
process.stderr.write('Error: the following middleware invoked next() more than once: ');
if (fn.name) {
console.error(fn.name + '()');
} else {
console.error('\n\n' + fn.toString() + '\n');
}
}
};

0 comments on commit 81d9f22

Please sign in to comment.