<commit_before>(function() {
  'use strict';

  angular.module('dimApp')
    .factory('dimXurService', XurService);

  XurService.$inject = ['$rootScope', '$q', 'dimBungieService', 'dimItemDefinitions', 'dimStoreService', '$http'];

  function XurService($rootScope, $q, dimBungieService, dimItemDefinitions, dimStoreService, $http) {
    var xurTest = false; // set this to true when you want to test but Xur's not around
    function xurTestData() {
      return $http.get('scripts/xur/xur.json')
        .then(function(json) {
          return json.data.Response.data;
        });
    }

    return {
      available: false,
      itemCategories: {},
      updateXur: function() {
        var self = this;
        var xurPromise = xurTest ? xurTestData() : dimBungieService.getXur();

        return xurPromise.then(function(xurData) {
          self.available = xurData && xurData.enabled;

          if (self.available) {
            dimItemDefinitions.then(function(itemDefs) {
              self.itemCategories = {};
              var rawItems = [];
              xurData.saleItemCategories.forEach(function(categoryData) {
                var wares = categoryData.saleItems.map(function(saleItem) {
                  rawItems.push(saleItem.item);
                  return {
                    cost: saleItem.costs[0].value,
                    currency: _.pick(itemDefs[saleItem.costs[0].itemHash], 'itemName', 'icon', 'itemHash'),
                    itemHash: saleItem.item.itemHash
                  };
                });
                self.itemCategories[categoryData.categoryTitle] = wares;
              });
              return dimStoreService.processItems(null, rawItems).then(function(items) {
                var itemsByHash = _.indexBy(items, 'hash');
                _.each(self.itemCategories, function(saleItems, category) {
                  saleItems.forEach(function(saleItem) {
                    saleItem.item = itemsByHash[saleItem.itemHash];
                    delete saleItem.itemHash;
                  });
                });
              });
            });
          }
        });
      }
    };<commit_msg>Harden XurService a bit against errors.<commit_after>(function() {
  'use strict';

  angular.module('dimApp')
    .factory('dimXurService', XurService);

  XurService.$inject = ['$rootScope', '$q', 'dimBungieService', 'dimItemDefinitions', 'dimStoreService', '$http'];

  function XurService($rootScope, $q, dimBungieService, dimItemDefinitions, dimStoreService, $http) {
    var xurTest = false; // set this to true when you want to test but Xur's not around
    function xurTestData() {
      return $http.get('scripts/xur/xur.json')
        .then(function(json) {
          return json.data.Response.data;
        });
    }

    return {
      available: false,
      itemCategories: {},
      updateXur: function() {
        var self = this;
        var xurPromise = xurTest ? xurTestData() : dimBungieService.getXur();

        return xurPromise.then(function(xurData) {
          self.available = xurData && xurData.enabled && xurData.saleItemCategories;

          if (self.available) {
            dimItemDefinitions.then(function(itemDefs) {
              self.itemCategories = {};
              var rawItems = [];
              xurData.saleItemCategories.forEach(function(categoryData) {
                var wares = categoryData.saleItems.map(function(saleItem) {
                  rawItems.push(saleItem.item);
                  return {
                    cost: saleItem.costs[0].value,
                    currency: _.pick(itemDefs[saleItem.costs[0].itemHash], 'itemName', 'icon', 'itemHash'),
                    itemHash: saleItem.item.itemHash
                  };
                });
                self.itemCategories[categoryData.categoryTitle] = wares;
              });
              return dimStoreService.processItems(null, rawItems).then(function(items) {
                var itemsByHash = _.indexBy(items, 'hash');
                _.each(self.itemCategories, function(saleItems, category) {
                  saleItems.forEach(function(saleItem) {
                    saleItem.item = itemsByHash[saleItem.itemHash];
                    delete saleItem.itemHash;
                  });
                });
              });
            });
          }
        });
      }
    };
{'fraction_non_alphanumeric': 0.11994485294117647, 'fraction_numerical': 0.0009191176470588235, 'mean_word_length': 1.9254032258064515, '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': '4323360', 'n_tokens_mistral': 1245, 'n_tokens_neox': 1164, 'n_words': 206}