lib/api.js
// Handle request time outs, return 500 in case of timeouts
Handle request time outs, return 500 in case of timeouts
Handle request time outs return 500 in case of timeouts
function handleRequestTimeouts(req, res, next) {
  var requestTimeout = parseInt(config.get().api_request_timeout) * 1000;
  if (requestTimeout <= 0) return next();
  var timeoutId = setTimeout(function() {
    logger.error('Timeout has occurred, request cannot be processed', { url: req.url });
    res.send(500);
  }, requestTimeout);
  var end = res.end;
  res.end = function(chunk, encoding) {
    clearTimeout(timeoutId);
    if (!res.headersSent) {
      res.end = end;
      res.end(chunk, encoding);
    }
  };
  next();
}
function handleRequestTimeouts ( req , res , next ) { var requestTimeout = parseInt ( config . get ( ) . api_request_timeout ) * 1000 ; if ( requestTimeout <= 0 ) return next ( ) ; var timeoutId = setTimeout ( function ( ) { logger . error ( 'Timeout has occurred, request cannot be processed' , { url : req . url } ) ; res . send ( 500 ) ; } , requestTimeout ) ; var end = res . end ; res . end = function ( chunk , encoding ) { clearTimeout ( timeoutId ) ; if ( ! res . headersSent ) { res . end = end ; res . end ( chunk , encoding ) ; } } ; next ( ) ; }
Handle request time outs, return 500 in case of timeouts
Handle request time outs return 500 in case of timeouts
// exit if disabled // timeout has happened, something bad has happened, send 500 back