Skip to content
This repository
Browse code

Merge branch 'error-handling-routes'

  • Loading branch information...
commit fee0f0dce066012631b039f43f634785f4f00af9 2 parents 02b9d0b + 0dd80e7
TJ Holowaychuk authored October 09, 2012
3  lib/router/index.js
@@ -159,7 +159,8 @@ Router.prototype._dispatch = function(req, res, next){
159 159
           if (fn.length < 4) return callbacks(err);
160 160
           fn(err, req, res, callbacks);
161 161
         } else if (fn) {
162  
-          fn(req, res, callbacks);
  162
+          if (fn.length < 4) return fn(req, res, callbacks);
  163
+          callbacks();
163 164
         } else {
164 165
           nextRoute(err);
165 166
         }
43  test/app.routes.error.js
... ...
@@ -0,0 +1,43 @@
  1
+var express = require('../')
  2
+  , request = require('./support/http');
  3
+
  4
+describe('app', function(){
  5
+  describe('.VERB()', function(){
  6
+    it('should only call an error handling routing callback when an error is propagated', function(done){
  7
+      var app = express();
  8
+
  9
+      var a = false;
  10
+      var b = false;
  11
+      var c = false;
  12
+      var d = false;
  13
+
  14
+      app.get('/', function(req, res, next){
  15
+        next(new Error('fabricated error'));
  16
+      }, function(req, res, next) {
  17
+        a = true;
  18
+        next();
  19
+      }, function(err, req, res, next){
  20
+        b = true;
  21
+        err.message.should.equal('fabricated error');
  22
+        next(err);
  23
+      }, function(err, req, res, next){
  24
+        c = true;
  25
+        err.message.should.equal('fabricated error');
  26
+        next();
  27
+      }, function(err, req, res, next){
  28
+        d = true;
  29
+        next();
  30
+      }, function(req, res){
  31
+        a.should.be.false;
  32
+        b.should.be.true;
  33
+        c.should.be.true;
  34
+        d.should.be.false;
  35
+        res.send(204);
  36
+      });
  37
+
  38
+      request(app)
  39
+      .get('/')
  40
+      .expect(204, done);
  41
+    })
  42
+  })
  43
+})

0 notes on commit fee0f0d

Please sign in to comment.
Something went wrong with that request. Please try again.