lib/getProxyTicket.js
function requestPT(path, callback, retryHandler) {
    logger.info('Trying to request proxy ticket from ', proxyPath);
    var startTime = Date.now(); 
    utils.getRequest(path, function(err, response) {
      /* istanbul ignore if */
      logger.access('|GET|' + path + '|' + (err ? 500 : response.status) + "|" + (Date.now() - startTime));
      if (err) {
        logger.error('Error happened when sending request to: ' + path);
        logger.error(err);
        return callback(err);
      }

      if (response.status !== 200) {
        logger.error('Request fail when trying to get proxy ticket', response);
        if (typeof retryHandler === 'function') return retryHandler(err);

        return callback(new Error('Request fail when trying to get proxy ticket, response status: ' + response.status +
          ', response body: ' + response.body));
      }

      var pt = parseCasResponse(response.body);

      if (pt) {
        logger.info('Request proxy ticket succeed, receive pt: ', pt);
        callback(null, pt);
      } else {
        logger.error('Can\' get pt from get proxy ticket response.');
        logger.error('Request for PT succeed, but response is invalid, response: ', response.body);
        if (typeof retryHandler === 'function') return retryHandler(new Error('Request for PT succeed, but response is invalid, response: ' + response.body));
        return callback(new Error('Request for PT succeed, but the response is invalid, response: ' + response.body));
      }
    });
  }
function requestPT(path, callback, retryHandler) {
    logger.info('Trying to request proxy ticket from ', proxyPath);
    var startTime = Date.now(); 
    utils.getRequest(path, function(err, response) {
      /* istanbul ignore if */
      logger.access('|GET|' + path + '|' + (err ? 500 : response.status) + "|" + (Date.now() - startTime));
      if (err) {
        logger.error('Error happened when sending request to: ' + path);
        logger.error(err);
        return callback(err);
      }

      if (response.status !== 200) {
        logger.error('Request fail when trying to get proxy ticket', response);
        if (typeof retryHandler === 'function') return retryHandler(err);

        return callback(new Error('Request fail when trying to get proxy ticket, response status: ' + response.status +
          ', response body: ' + response.body));
      }

      var pt = parseCasResponse(response.body);

      if (pt) {
        logger.info('Request proxy ticket succeed, receive pt: ', pt);
        callback(null, pt);
      } else {
        logger.error('Can\' get pt from get proxy ticket response.');
        logger.error('Request for PT succeed, but response is invalid, response: ', response.body);
        if (typeof retryHandler === 'function') return retryHandler(new Error('Request for PT succeed, but response is invalid, response: ' + response.body));
        return callback(new Error('Request for PT succeed, but the response is invalid, response: ' + response.body));
      }
    });
  }
function requestPT ( path , callback , retryHandler ) { logger . info ( 'Trying to request proxy ticket from ' , proxyPath ) ; var startTime = Date . now ( ) ; utils . getRequest ( path , function ( err , response ) { /* istanbul ignore if */ logger . access ( '|GET|' + path + '|' + ( err ? 500 : response . status ) + "|" + ( Date . now ( ) - startTime ) ) ; if ( err ) { logger . error ( 'Error happened when sending request to: ' + path ) ; logger . error ( err ) ; return callback ( err ) ; } if ( response . status !== 200 ) { logger . error ( 'Request fail when trying to get proxy ticket' , response ) ; if ( typeof retryHandler === 'function' ) return retryHandler ( err ) ; return callback ( new Error ( 'Request fail when trying to get proxy ticket, response status: ' + response . status + ', response body: ' + response . body ) ) ; } var pt = parseCasResponse ( response . body ) ; if ( pt ) { logger . info ( 'Request proxy ticket succeed, receive pt: ' , pt ) ; callback ( null , pt ) ; } else { logger . error ( 'Can\' get pt from get proxy ticket response.' ) ; logger . error ( 'Request for PT succeed, but response is invalid, response: ' , response . body ) ; if ( typeof retryHandler === 'function' ) return retryHandler ( new Error ( 'Request for PT succeed, but response is invalid, response: ' + response . body ) ) ; return callback ( new Error ( 'Request for PT succeed, but the response is invalid, response: ' + response . body ) ) ; } } ) ; }
Request a proxy ticket
@param req
@param path
@param callback
@param {Function} retryHandler If this callback is set, it will be called only if request failed due to authentication issue.
Request a proxy ticket