code: function next(err) {
              var middleware = stack[index++];
  
              // No more middlewares or early end.
              if (!middleware || ended) {
                  if (out) out(err, ctx);
                  return;
              }
  
              // Check if middleware type matches or if it has no type.
              if (middleware.type.indexOf(type) === -1 && middleware.type.length > 0) {
                  return next(err);
              }
  
              try {
                  var arity = middleware.cb.length;
                  //if err, only execute error middlewares
                  if (err) {
                      //error middlewares have an arity of 3, the first
                      //arg being the error
                      if (arity === 3) {
                          middleware.cb(err, ctx, next);
                      } else {
                          next(err);
                      }
                  } else if (arity < 2) {
                      middleware.cb(ctx);
                      next();
                  } else if (arity < 3) {
                      middleware.cb(ctx, next);
                  } else {
                      next();
                  }
              }
              catch (e) {
                  next(e);
              }
          }
docs: Handle next middleware in stack.