<commit_before>import 'conductor' as Conductor;

var AuthenticatedGithubApiService = Conductor.Oasis.Service.extend({

  accessToken: function(){
    return this.userController.get('accessToken');
  },
  /*
    @public

    @property requests
    @type Object
  */
  requests: {

    /*
      @public

      @method ajax
      @param promise {Conductor.Oasis.RSVP.Promise}
      @param ajaxOpts {Object}
    */
    ajax: function(promise, ajaxOpts) {
      var accessToken = this.accessToken();
      if (!accessToken) {
        promise.reject();
        return;
      }

      if (!ajaxOpts.data) {
        ajaxOpts.data = {};
      }

      ajaxOpts.url = 'https://api.github.com' + ajaxOpts.url;
      ajaxOpts.beforeSend = function(xhr){
        xhr.setRequestHeader('Authorization', "token " + accessToken);
      };
      console.log('AuthenticatedGithubApiService.ajax', ajaxOpts);

      $.ajax(ajaxOpts).then(function(value){
        promise.resolve(value);
      }).then(null, function(jqXhr) {
        promise.reject(failureResultFromJqXhr(jqXhr));
      });
    }
  }
});

function failureResultFromJqXhr(jqXhr){
  return {
    responseText: jqXhr.responseText,
    status: jqXhr.status,
    rawHeaders: jqXhr.getAllResponseHeaders()
  };
}
export = AuthenticatedGithubApiService;<commit_msg>reject with an error (one that preserves the stack)<commit_after>import 'conductor' as Conductor;

var AuthenticatedGithubApiService = Conductor.Oasis.Service.extend({

  accessToken: function(){
    return this.userController.get('accessToken');
  },
  /*
    @public

    @property requests
    @type Object
  */
  requests: {

    /*
      @public

      @method ajax
      @param promise {Conductor.Oasis.RSVP.Promise}
      @param ajaxOpts {Object}
    */
    ajax: function(promise, ajaxOpts) {
      var accessToken = this.accessToken();

      if (!accessToken) {
        try {
          throw new Error('no gthub acccess token');
        } catch(error) {
          promise.reject(error);
        }
        return;
      }

      if (!ajaxOpts.data) {
        ajaxOpts.data = {};
      }

      ajaxOpts.url = 'https://api.github.com' + ajaxOpts.url;
      ajaxOpts.beforeSend = function(xhr){
        xhr.setRequestHeader('Authorization', "token " + accessToken);
      };
      console.log('AuthenticatedGithubApiService.ajax', ajaxOpts);

      $.ajax(ajaxOpts).then(function(value){
        promise.resolve(value);
      }).then(null, function(jqXhr) {
        promise.reject(failureResultFromJqXhr(jqXhr));
      }).then(null, Conductor.error);
    }
  }
});

function failureResultFromJqXhr(jqXhr){
  return {
    responseText: jqXhr.responseText,
    status: jqXhr.status,
    rawHeaders: jqXhr.getAllResponseHeaders()
  };
}
export = AuthenticatedGithubApiService;
{'fraction_non_alphanumeric': 0.12931034482758622, 'fraction_numerical': 0.0, 'mean_word_length': 2.7483176312247646, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '3092462', 'n_tokens_mistral': 914, 'n_tokens_neox': 886, 'n_words': 147}