New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

directly invoke error middleware #1085

Closed
wants to merge 5 commits into
base: master
from
Jump to file or symbol
Failed to load files and symbols.
+4 −9
Diff settings

Always

Just for now

Viewing a subset of changes. View all

directly next error middleware not return next(err)

  • Loading branch information...
流香
流香 committed Sep 10, 2016
commit c93abc7bb54c08dfc6eb8b98eac9fb5b2e920697
View
@@ -107,9 +107,9 @@ proto.use = function use(route, fn) {
// add the middleware
debug('use %s %s', path || '/', handle.name || 'anonymous');
if (handle.length === 4) {
this.errware.push({ route: path, handle: handle, index:this.stack.length })
this.errware.push({ route: path, handle: handle, index:this.stack.length });
} else {
this.stack.push({ route: path, handle: handle });
this.stack.push({ route: path, handle: handle, index:this.errware.length });
}
return this;
@@ -155,8 +155,10 @@ proto.handle = function handle(req, res, out) {
var layer;
if (err) {
layer = errware[errIndex++];
if (layer) index = layer.index;
} else {
layer = stack[index++];
if (layer) errIndex = layer.index;
}
// all done
@@ -165,13 +167,6 @@ proto.handle = function handle(req, res, out) {
return;
}
if (layer.index !== undefined) {
// ignore prev error middleware
if (index > layer.index) return next(err);
// move to non-error index
index = layer.index;
}
// route data
var path = parseUrl(req).pathname || '/';
var route = layer.route;
ProTip! Use n and p to navigate between commits in a pull request.