Removed `app.error()`. Closes #733
Before adoption: this commit came in with the history the project adopted, so no landing records it.
use trailing middleware with arity of 4 as shown in this issue. They are functionally equivalent
authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 261203d · Browse files · 2 files·+0 added−102 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+0 added−102 removed
- tests:+0 added−59 removed
- other:+0 added−43 removed
Provenance
- Commit
456a985- Tree
5283216- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
261203d
2 files changed+0 added−102 removed
modified:lib/http.js-43 removed
62 unmodified lines63 this.redirects = {};64 this.isCallbacks = {};65 this._locals = {};66 this.dynamicViewHelpers = {};67- this.errorHandlers = [];67 68 this.set('home', '/');69 this.set('env', process.env.NODE_ENV || 'development');70 38 unmodified lines109 this.configure('production', function(){110 this.enable('view cache');111 });112 114- // register error handlers on "listening"115- // so that they disregard definition position.116- this.on('listening', this.registerErrorHandlers.bind(this));117-113 // route manipulation methods114 methods.forEach(function(method){115 self.lookup[method] = function(path){116 return self.routes.lookup(method, path);51 unmodified lines168 return this.routes.match('all', url);169 };170 171 /**177- * When using the vhost() middleware register error handlers.178- */179-180-app.onvhost = function(){181- this.registerErrorHandlers();182-};183-184-/**185- * Register error handlers.186- *187- * @return {Server} for chaining188- * @api public189- */190-191-app.registerErrorHandlers = function(){192- this.errorHandlers.forEach(function(fn){193- this.use(function(err, req, res, next){194- fn.apply(this, arguments);195- });196- }, this);197- return this;198-};199-200-/**172 * Proxy `connect.HTTPServer#use()` to apply settings to173 * mounted applications.174 *175 * @param {String|Function|Server} route151 unmodified lines327 return this;328 };329 330 /**360- * Assign a custom exception handler callback `fn`.361- * These handlers are always _last_ in the middleware stack.362- *363- * @param {Function} fn364- * @return {Server} for chaining365- * @api public366- */367-368-app.error = function(fn){369- this.errorHandlers.push(fn);370- return this;371-};372-373-/**331 * Register the given callback `fn` for the given `type`.332 *333 * @param {String} type334 * @param {Function} fn167 unmodified linesmodified:test/express.test.js-59 removed
128 unmodified lines129 beforeExit(function(){130 calls.should.eql(['one', 'two']);131 });132 },133- 134- 'test #error()': function(){135- // Passing down middleware stack136- var app = express.createServer();137- 138- app.get('/', function(req, res, next){139- next(new Error('broken'));140- });141- 142- app.use('/', connect.errorHandler());143- 144- assert.response(app,145- { url: '/' },146- { body: 'Internal Server Error' });133 148- // Custom handler149- var app = express.createServer();150- 151- app.error(function(err, req, res){152- res.send('Shit: ' + err.message, 500);153- });154-155- app.get('/', function(req, res, next){156- next(new Error('broken'));157- });158- 159- assert.response(app,160- { url: '/' },161- { body: 'Shit: broken', status: 500 });162- 163- // Multiple error()s164- var app = express.createServer();165- 166- app.error(function(err, req, res, next){167- if (err.message === 'broken') {168- next(err);169- } else {170- res.send(500);171- }172- });173- 174- app.error(function(err, req, res, next){175- res.send(err.message, 500);176- });177-178- app.get('/', function(req, res, next){179- throw new Error('broken');180- });181- app.get('/foo', function(req, res, next){182- throw new Error('oh noes');183- });184- 185- assert.response(app,186- { url: '/' },187- { body: 'broken', status: 500 });188- assert.response(app,189- { url: '/foo' },190- { body: 'Internal Server Error' });191- },192- 134 'test next()': function(){135 var app = express.createServer();136 137 app.get('/user.:format?', function(req, res, next){296 unmodified lines