This is because Express is never able to catch the exception that occurred in the /asyncerror example, because you are throwing it out of the async callback context, not the Express middleware context. In the general case, if you do not want the error condition in the asynchronous function to cause your node application to crash, report the error with a callback rather than sending it. In this case, you can call the next parameter, which receives your app.get , but you are not using it. Try instead:
app.get('/asyncerror', function(req, res, next){ var that = this; async.waterfall([ function(next){ console.log('1'); next("42", "2"); }, function(arg, next) { console.log(arg); res.json('ok'); next(); } ], function(err){ console.log(this); next(Error('Aie')); }); });
source share