After each filter, this check ensures that the returned request options are valid. Again, any error is caught by the promise chain and causes the returned promise to be rejected.
328582
function(filterIndex, options) {
      if (options === undefined) {
        throw new Error('Request filter at index ' + filterIndex + ' returned nothing; it must return the filtered request options');
      } else if (!_.isObject(options)) {
        throw new Error('Expected request filter at index ' + filterIndex + ' to return the request options as an object, got ' + typeof(options));
      }

      return options;
    }
784693
function checkIfMatch(req, res, next) {
    var clientETags;
    var cur;
    var etag = res.etag || res.getHeader('etag') || '';
    var ifMatch;
    var matched = false;

    if ((ifMatch = req.headers['if-match'])) {

        clientETags = ifMatch.split(/\s*,\s*/);

        for (var i = 0; i < clientETags.length; i++) {
            cur = clientETags[i];

            // only strong comparison

            cur = cur.replace(/^W\//, '');
            cur = cur.replace(/^"(\w*)"$/, '$1');

            if (cur === '*' || cur === etag) {
                matched = true;
                break;
            }
        }

        if (!matched) {
            var err = new PreconditionFailedError(IF_MATCH_FAIL,
                ifMatch,
                etag);
            return (next(err));
        }
    }

    return (next());
}
74303
function validate(req, res, callback, options) {
  // check ticket first`
  var ticket = req.query && req.query.ticket || null;
  var session = req.session;
  var lastUrl = utils.getLastUrl(req, options);
  var logger = utils.getLogger(req, options);

  logger.info('Start validating ticket...');

  if (ticket) {
    logger.info('Find ticket in query', ticket);
    if (session && session.cas && session.cas.st && session.cas.st === ticket) {
      logger.info('Ticket in query is equal to the one in session, go last url: ' + lastUrl);
      return callback(function(req, res, next) {
        res.redirect(302, lastUrl);
      });
    }

    validateTicket(req, options, function(err, response) {
      /* istanbul ignore if */
      if (err) {
        return callback(function(req, res, next) {
          res.status(500).send({
            message: 'Receive response from cas when validating ticket, but request failed because an error happened.',
            error: err.message
          });
        });
      }

      logger.info('Receive from CAS server, status: ' + response.status);
      if (response.status === 200) {

        parseCasResponse(response.body, logger, function(err, info) {
          if (err) {
            var resBody = {
              error: err
            };
            if (info && info.message) resBody.message = info.message;
            return callback(function(req, res, next) {
              res.status(500).send(resBody);
            });
          }

          if (!info || (info && !info.user)) {
            return callback(function(req, res, next) {
              res.status(401).send({
                message: 'Receive response from CAS when validating ticket, but the validation is failed.'
              });
            })
          }

          var pgtIou = info.proxyGrantingTicket;

          delete info.proxyGrantingTicket;

          req.session.cas = info;

          var ticket = req.query.ticket;

          req.session.cas.st = ticket;

          if (options.slo) {
            req.sessionStore.set(ticket, { sid: req.session.id, cookie: req.session.cookie }, function(err) {
              /* istanbul ignore if */
              if (err) {
                logger.info('Trying to store ticket in sessionStore for ssoff failed!');
                logger.error(err);
              }
            });
          }

          if (!pgtIou) {
            if (options.paths.proxyCallback) {
              logger.error('pgtUrl is specific, but havn\'t find pgtIou from CAS validation response! Response status 401.');
              return callback(function(req, res, next) {
                res.status(401).send({
                  message: 'pgtUrl is specific, but havn\'t find pgtIou from CAS validation response!'
                });
              });
            } else {
              logger.info('None-proxy mode, validate ticket succeed, redirecting to lastUrl: ' + lastUrl);
              req.session.save(function(err) {
                /* istanbul ignore if */
                if (err) {
                  logger.error('Trying to save session failed!');
                  logger.error(err);
                  return callback(function(req, res, next) {
                    res.status(500).send({
                      message: 'Trying to save session failed!',
                      error: err
                    });
                  });
                }

                lastUrl = getLastUrl(req, res, options, logger, lastUrl);

                return callback(function(req, res, next) {
                  res.redirect(302, lastUrl);
                });
              });
            }

            return;
          }

          retrievePGTFromPGTIOU(req, res, callback, pgtIou, options);
        });
      }
      else {
        logger.error('Receive response from cas when validating ticket, but request failed with status code: ' + response.status + '!');
        callback(function(req, res, next) {
          res.status(401).send({
            message: 'Receive response from cas when validating ticket, but request failed with status code: ' + response.status + '.'
          });
        });
      }
    });
  } else {
    lastUrl = utils.getLastUrl(req, options);
    logger.info('Can\' find ticket in query, redirect to last url: ' + lastUrl);
    return callback(function(req, res, next) {
      res.redirect(302, lastUrl);
    });
  }
}
4741
function catchResults (resolve, reject, err, client, done) {
	//debug.log('catchResults()...');
	if (err) {
		return reject(err);
	}
	resolve({"client":client, "done":done});
}
45683
function Request__chain(promise, next) {

        if (!promise) {
            return new Promise(function (resolve, reject) {
                try {
                    resolve(next.apply(next, arguments));
                } catch (e) {
                    reject(new error.HttpError(500, {}, "Error on executing action", e));
                }
            });
        }

        return promise.then(function (data) {
            if (!!this.isPromiseChainStopped) {
                return promise;
            }
            return _handler(data);
        }.bind(this), this._handleError.bind(this));

        function _handler() {
            try {
                return next.apply(next, arguments);
            } catch (e) {
                throw new error.HttpError(500, {}, "Error on executing action", e);
            }
        }
    }
275238
function(d, err, result) {
    if (err) {
        d.reject(err);
    }
    else {
        d.resolve(result);
    }
}
1020353
function checkAllowedTypes(options) {
            if (allowedTypes[options.type] === undefined) {
                return Promise.reject(new common.errors.BadRequestError({message: common.i18n.t('errors.api.slugs.unknownSlugType', {type: options.type})}));
            }
            return options;
        }
472760
function (promise){
    		promise.success = function (fn) {
	            promise.then(fn);
	            return promise;
	        };

	        promise.error = function (fn) {
	            promise.then(null, fn);
	            return promise;
	        };
    	}
490054
function(error) {
		var that = this,
			param = this.chainParameter,
			stopPointer = {},
			utils = {
				stop: null,
				url: this.scraper.url,
				scraper: this,
				params: param,
				lastReturn: undefined
			},
			keep = true;
		this.chainParameter = null;

		if (error) {
			this.errorCallback(error, utils);
			this.doneCallback(utils);
			return;
		}

		async.eachSeries(this.promises, function dispatcher(fn, callback) {
			var done = function(err, lastReturn) {
				utils.lastReturn = lastReturn;
				if (err === stopPointer) {
					keep = false;
					callback(err);
				} else if (err) {
					callback(err);
				} else if (keep) {
					callback();
				}
			};
			utils.stop = function() {
				done(stopPointer, null);
			};

			try {
				fn.call(that, done, utils);
			} catch (err) {
				done(err, null);
			}
		}, function(err) {
			utils.stop = null;
			if (err && err !== stopPointer) {
				that.errorCallback(err, utils);
			}
			that.doneCallback(utils.lastReturn, utils);
			that.scraper.close();
		});
	}
976409
def check_filter_validity(self, reply, filter_str):
        
        try:
            f_ind = reply.index(filter_str)
            l_ind = reply.rindex(filter_str)
        except Exception:
            fail_reason = vdp_const.filter_failure_reason % (reply)
            LOG.error("%s", fail_reason)
            return False, fail_reason
        if f_ind != l_ind:
            # Currently not supported if reply contains a filter keyword
            fail_reason = vdp_const.multiple_filter_failure_reason % (reply)
            LOG.error("%s", fail_reason)
            return False, fail_reason
        return True, None
1050396
function verifyOptions(options) {
	if (!pa11y.allowedStandards.includes(options.standard)) {
		throw new Error(`Standard must be one of ${pa11y.allowedStandards.join(', ')}`);
	}
	if (options.page && !options.browser) {
		throw new Error('The page option must only be set alongside the browser option');
	}
}
775415
function reject(vReason) {
			vResult = vReason;
			iState = -1;

			if (!bCaught && SyncPromise.listener) {
				SyncPromise.listener(that, false);
			}

			if (fnReject) {
				fnReject(vReason);
				fnReject = fnResolve = null; // be nice to the garbage collector
			}
		}
553500
public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		int localPort = request.getLocalPort();
		if (mode == MODE_ALLOW && !portHit(localPort) ||
				mode == MODE_DENY && portHit(localPort)){
			if (message == null){
				((HttpServletResponse) response).sendError(statusCode, ((HttpServletRequest)request).getRequestURI());
			}else if (message.length() == 0){
				((HttpServletResponse) response).sendError(statusCode);
			}else{
				((HttpServletResponse) response).sendError(statusCode, message);
			}
		}else{
			chain.doFilter(request, response);
		}
	}
212132
function fin(promise, finalPromiseFactory) {
  return promise.then(function (res) {
    return finalPromiseFactory().then(function () {
      return res;
    });
  }, function (reason) {
    return finalPromiseFactory().then(function () {
      throw reason;
    });
  });
}
494950
def reject(self, reason):
        """"""
        if self._state != 'pending':
            raise RuntimeError('Promise is no longer pending.')

        self.reason = reason
        self._state = 'rejected'
        errbacks = self._errbacks
        self._errbacks = None
        for errback in errbacks:
            errback(reason)
1229096
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		try {
			HttpServletRequest hreq = (HttpServletRequest)request;
			if(noAuthn(hreq)) {
				chain.doFilter(request, response);
			} else {
				HttpServletResponse hresp = (HttpServletResponse)response;
				TafResp tresp = httpChecker.validate(hreq, hresp);
				if(tresp.isAuthenticated()==RESP.IS_AUTHENTICATED) {
						CadiWrap cw = new CadiWrap(hreq, tresp, httpChecker.getLur(),getConverter(hreq));
						if(httpChecker.notCadi(cw, hresp)) {
							chain.doFilter(cw,response);
						}
				}						
			}
		} catch (ClassCastException e) {
			throw new ServletException("CadiFilter expects Servlet to be an HTTP Servlet",e);
		}
	}
519951
function({options}, succeed, skip) {
    var ok;
    if (!Array.isArray(options.if)) {
      options.if = [options.if];
    }
    ok = true;
    return each(options.if).call((si, next) => {
      var err, type;
      if (!ok) {
        return next();
      }
      type = typeof si;
      if (si === null || type === 'undefined') {
        ok = false;
        return next();
      } else if (type === 'boolean' || type === 'number') {
        if (!si) {
          ok = false;
        }
        return next();
      } else if (type === 'function') {
        if (si.length < 2) {
          try {
            if (!si.call(this, {
              options: options
            })) {
              ok = false;
            }
            return next();
          } catch (error) {
            err = error;
            return next(err);
          }
        } else if (si.length === 2) {
          try {
            return si.call(this, {
              options: options
            }, (err, is_ok) => {
              if (err) {
                return next(err);
              }
              if (!is_ok) {
                ok = false;
              }
              return next();
            });
          } catch (error) {
            err = error;
            return next(err);
          }
        } else {
          return next(Error(`Invalid argument length, expecting 2 or less, got ${si.length}`));
        }
      } else if (type === 'string' || (type === 'object' && Buffer.isBuffer(si))) {
        si = template(si.toString(), {
          options: options
        });
        if (si.length === 0) {
          ok = false;
        }
        return next();
      } else {
        return next(Error(`Invalid condition "if": ${JSON.stringify(si)}`));
      }
    }).next(function(err) {
      if (err || !ok) {
        return skip(err);
      } else {
        return succeed();
      }
    });
  }