nl_tokens: PrivateFunction : processCallbacks This function is used to run a callback function or an array of stacked callback functions which are registered for an API route .
pl_tokens: function processCallbacks ( namedRouteParameters , data , req , res , successHandler , errorHandler , callbacks ) { debug ( 'processing callbacks (url: `%s`, namedRouteParameters: `%s`,' + ' data: `%j`)' , req . url , namedRouteParameters , data ) ; var callbackScope = { app : req . app , req : req } , handlerScope = { app : req . app , req : req , res : res } , callbackArguments = _ . union ( successHandler . bind ( handlerScope ) , errorHandler . bind ( handlerScope ) , namedRouteParameters , data ) , index = - 1 , executeCallback = function executeCallback ( callback ) { callback . apply ( callbackScope , callbackArguments ) ; } , runner ; if ( ! _ . isArray ( callbacks ) ) { runner = function ( ) { executeCallback ( callbacks ) ; } ; } else { var finalSuccessHandler = callbackArguments [ 0 ] , stackedSuccessHandler = function stackedSuccessHandler ( ) { index += 1 ; if ( index < callbacks . length ) { executeCallback ( callbacks [ <mask> ] ) ; } else { finalSuccessHandler . apply ( handlerScope , arguments ) ; } } ; callbackArguments [ 0 ] = stackedSuccessHandler ; runner = stackedSuccessHandler ; } try { runner ( ) ; } catch ( err ) { winston . log ( 'error' , 'API callback caused exceptional error' , { source : toString ( ) , apiRoute : req . originalUrl , err : err . toString ( ) || err , stack : err . stack || undefined } ) ; errorHandler . call ( handlerScope , err ) ; } }