<commit_before>'use strict';

/**
 * Download the RELEASE fil
 *
 * (c) 2015 <NAME>
 */

// == Load libraries
var logSymbols = require('log-symbols');
var Promise    = require('promise');
var request    = require('request');

// == Download release file

/**
 * Load RELEASE information
 * @return Promise
 */
var loadReleaseFile = function(repositoryUrl) {
  var promise = new Promise(function(resolve, reject) {
    var req = request.get(repositoryUrl + '/RELEASE', function(error, res, body) {
      if(!error && res.statusCode == 200) { // HTTP OK
        resolve(body); 
      }
      else {
        reject('Download failed. Server sent status code ' + res.statusCode);
      }
    });

    // Handle HTTP (connection) error
    req.on('error', function(err) {
      // Display error message
      console.error(
        logSymbols.error + ' Could not download RELEASE - ' + err
      );
      reject(err);
    });

  });<commit_msg>Better error handling. (Fixes issu issue #3)<commit_after>'use strict';

/**
 * Download the RELEASE fil
 *
 * (c) 2015 <NAME>
 */

// == Load libraries
var logSymbols = require('log-symbols');
var Promise    = require('promise');
var request    = require('request');

// == Download release file

/**
 * Load RELEASE information
 * @return Promise
 */
var loadReleaseFile = function(repositoryUrl) {
  var promise = new Promise(function(resolve, reject) {
    var req = request.get(repositoryUrl + '/RELEASE', function(error, res, body) {
      if(error) {
        reject(error);
        return;
      }

      if(res.statusCode == 200) { // HTTP OK
        resolve(body); 
      }
      else {
        reject('Download failed. Server sent status code ' + res.statusCode);
      }
    });

    // Handle HTTP (connection) error
    req.on('error', function(err) {
      // Display error message
      console.error(
        logSymbols.error + ' Could not download RELEASE - ' + err
      );
      reject(err);
    });

  });
{'fraction_non_alphanumeric': 0.14416709118695872, 'fraction_numerical': 0.007641365257259297, 'mean_word_length': 2.545126353790614, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6805673', 'n_tokens_mistral': 589, 'n_tokens_neox': 563, 'n_words': 156}