function fetchState() {
  return new Promise(function (resolve, reject) {
    var url = 'http://' + config.collector.host + ':' + config.collector.port + '/state';
    var body = '';
    console.log('Fetch state at url', url);
    http.get(url, function (res) {
      res.on('data', function (chunk) {
        body += chunk;
      });

      res.on('error', function (err) {
        reject(err);
      });

      res.on('end', function () {
        try {
          var data = JSON.parse(body);
          resolve(data);
        } catch (err) {
          reject(err);
        }
      });
    });
  });
}
/*
  Fetch contents of <collector>/state and parse as JSON
  Resolves: JSON data as object
  Rejects : on HTTP error or JSON parsing error
*/
Fetch contents of /state and parse as JSON
Resolves: JSON data as object
Rejects : on HTTP error or JSON parsing error
Fetch contents of / state and parse as JSON Resolves : JSON data as object Rejects : on HTTP error or JSON parsing error
function fetchState() {
  return new Promise(function (resolve, reject) {
    var url = 'http://' + config.collector.host + ':' + config.collector.port + '/state';
    var body = '';
    console.log('Fetch state at url', url);
    http.get(url, function (res) {
      res.on('data', function (chunk) {
        body += chunk;
      });
      res.on('error', function (err) {
        reject(err);
      });
      res.on('end', function () {
        try {
          var data = JSON.parse(body);
          resolve(data);
        } catch (err) {
          reject(err);
        }
      });
    });
  });
}
function fetchState ( ) { return new Promise ( function ( resolve , reject ) { var url = 'http://' + config . collector . host + ':' + config . collector . port + '/state' ; var body = '' ; console . log ( 'Fetch state at url' , url ) ; http . get ( url , function ( res ) { res . on ( 'data' , function ( chunk ) { body += chunk ; } ) ; res . on ( 'error' , function ( err ) { reject ( err ) ; } ) ; res . on ( 'end' , function ( ) { try { var data = JSON . parse ( body ) ; resolve ( data ) ; } catch ( err ) { reject ( err ) ; } } ) ; } ) ; } ) ; }
Fetch contents of <collector>/state and parse as JSON
Resolves: JSON data as object
Rejects : on HTTP error or JSON parsing error
Fetch contents of <collector > / state and parse as JSON Resolves : JSON data as object Rejects : on HTTP error or JSON parsing error