<commit_before>'use strict';
var Q = require('q');
var _ = require('lodash');
var restler = require('restler');

var httpVerbs = ['request', 'get', 'post', 'put', 'del', 'head', 'patch'];
var jsonMethods =['json', 'postJson', 'putJson'];

// Function that generate the restler wrapper for all the basic http verbs to return promise
_.forEach(httpVerbs, function(verb){
  exports[verb] = function(url, options){
    var d = Q.defer();
    restler[verb](url, options).on('complete', function(result, response){
      if (result instanceof Error) {
        d.reject(result)
      } else {
        d.resolve({'data': result, 'response':response});
      }
    }).on('error', function(err, response){
      d.reject({'error': err, 'response': response });
    }).on('timeout', function(ms){
      d.reject({'name': 'timeout', 'message':'Timeout after '+ms+'ms'});
    });
    return d.promise;
  };
});

// Function that generate the restler wrapper for all the json methods to return promise
_.forEach(jsonMethods, function(verb){
  exports[verb] = function(url, data, options){
    var d = Q.defer();
    restler[verb](url, data, options).on('complete', function(result, response){
      if (result instanceof Error) {
        d.reject(result)
      } else {
        d.resolve({'data': result, 'response':response});
      }
    }).on('error', function(err, response){
      d.reject({'error': err, 'response': response });
    }).on('timeout', function(ms){
      d.reject({'name': 'timeout', 'message':'Timeout after '+ms+'ms'});
    });
    return d.promise;
  };
});<commit_msg>fixing return on error<commit_after>'use strict';
var Q = require('q');
var _ = require('lodash');
var restler = require('restler');

var httpVerbs = ['request', 'get', 'post', 'put', 'del', 'head', 'patch'];
var jsonMethods =['json', 'postJson', 'putJson'];

// Function that generate the restler wrapper for all the basic http verbs to return promise
_.forEach(httpVerbs, function(verb){
  exports[verb] = function(url, options){
    var d = Q.defer();
    restler[verb](url, options).on('complete', function(result, response){
      if (result instanceof Error) {
        d.reject(result)
      } else {
        d.resolve({'data': result, 'response':response});
      }
    }).on('error', function(error){
      d.reject(error);
    }).on('timeout', function(ms){
      d.reject({'name': 'timeout', 'message':'Timeout after '+ms+'ms'});
    });
    return d.promise;
  };
});

// Function that generate the restler wrapper for all the json methods to return promise
_.forEach(jsonMethods, function(verb){
  exports[verb] = function(url, data, options){
    var d = Q.defer();
    restler[verb](url, data, options).on('complete', function(result, response){
      if (result instanceof Error) {
        d.reject(result)
      } else {
        d.resolve({'data': result, 'response':response});
      }
    }).on('error', function(error){
      d.reject(error);
    }).on('timeout', function(ms){
      d.reject({'name': 'timeout', 'message':'Timeout after '+ms+'ms'});
    });
    return d.promise;
  };
});
{'fraction_non_alphanumeric': 0.19047619047619047, 'fraction_numerical': 0.0, 'mean_word_length': 3.7217125382262997, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1814591', 'n_tokens_mistral': 941, 'n_tokens_neox': 932, 'n_words': 253}