lib/common/route.js
function applyCatchList(promise, req, res, catchList, index) {
    index = index || 0;

    if (   !Array.isArray(catchList)
        || index > catchList.length - 1
        || !Array.isArray(catchList[index])
        || !(catchList[index][1] instanceof Function)
    ) {
        return promise;
    }

    var args = _.clone(catchList[index]);
    var cb = args[1];

    args[1] = function(err) {
        return cb(err, req, res);
    };

    promise = promise.catch.apply(promise, args);
    return applyCatchList(promise, req, res, catchList, ++index);
}
function applyCatchList(promise, req, res, catchList, index) {
    index = index || 0;

    if (   !Array.isArray(catchList)
        || index > catchList.length - 1
        || !Array.isArray(catchList[index])
        || !(catchList[index][1] instanceof Function)
    ) {
        return promise;
    }

    var args = _.clone(catchList[index]);
    var cb = args[1];

    args[1] = function(err) {
        return cb(err, req, res);
    };

    promise = promise.catch.apply(promise, args);
    return applyCatchList(promise, req, res, catchList, ++index);
}
function applyCatchList ( promise , req , res , catchList , index ) { index = index || 0 ; if ( ! Array . isArray ( catchList ) || index > catchList . length - 1 || ! Array . isArray ( catchList [ index ] ) || ! ( catchList [ index ] [ 1 ] instanceof Function ) ) { return promise ; } var args = _ . clone ( catchList [ index ] ) ; var cb = args [ 1 ] ; args [ 1 ] = function ( err ) { return cb ( err , req , res ) ; } ; promise = promise . catch . apply ( promise , args ) ; return applyCatchList ( promise , req , res , catchList , ++ index ) ; }
applies collection of catch handler functions to provided Promise object

@private

@param {Promise} promise - the promise catch functions are going to be applied to
@param {Object}  req
@param {Object}  res
@param {Array}   catchList - array of arrays - each item of array is a pair of [ErrorFilterConstructor,FunctionErrHandler]
@return {Promise}
applies collection of catch handler functions to provided Promise object