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

  angular.module('dimApp')
    .factory('dimBungieService', BungieService);

  BungieService.$inject = ['$rootScope', '$q', '$timeout', '$http', 'dimState', 'toaster'];

  function BungieService($rootScope, $q, $timeout, $http, dimState, toaster) {
    var apiKey = '<KEY>';
    var tokenPromise = null;
    var platformPromise = null;
    var membershipPromise = null;

    $rootScope.$on('dim-active-platform-updated', function() {
      tokenPromise = null;
      platformPromise = null;
      membershipPromise = null;
    });

    var service = {
      getPlatforms: getPlatforms,
      getCharacters: getCharacters,
      getStores: getStores,
      transfer: transfer,
      equip: equip,
      equipItems: equipItems,
      setItemState: setItemState,
      getXur: getXur,
      getVendors: getVendors
    };

    return service;

    function assignResultAndForward(dataset, attribute, result) {
      dataset[attribute] = result;

      return result;
    }

    function handleErrors(response) {
      if (response.status === 503) {
        return $q.reject(new Error("Bungie.net is down."));
      }
      if (response.status < 200 || response.status >= 400) {
        return $q.reject(new Error('Network error: ' + response.status));
      }

      var errorCode = response.data.ErrorCode;
      if (errorCode === 36) {
        return $q.reject(new Error('Bungie API throttling limit exceeded. Please wait a bit and then retry.'));
      } else if (errorCode === 99) {
        openBungieNetTab();
        return $q.reject(new Error('Please log into Bungie.net in order to use this extension.'));
      } else if (errorCode === 5) {
        return $q.reject(new Error('Bungie.net servers are down for maintenance.'));
      } else if (errorCode === 1618 &&
                 response.config.url.indexOf('/Account/') >= 0 &&
                 response.config.url.indexOf('/Character/') < 0) {
        return $q.reject(new Error('No Destiny account was found for this platform.'));
      } else if (errorCode > 1) {
        return $q.reject(new Error(response.data.Message));
      }

      return response;
    }

    function retryOnThrottled(request) {
      var a = $q(function(resolve, reject) {
        var retries = 4;

        function run() {
          $http(request).then(function success(response) {
            if (response.data.ErrorCode === 36) {
              retries = retries - 1;

              if (retries <= 0) {
                // debugger;
                resolve(response);
              } else {
                $timeout(run, Math.pow(2, 4 - retries) * 1000);
              }
            } else {
              resolve(response);
            }
          }, function failure(response) {
            // debugger;
            if (response.data) {
              reject(new Error(response.data.Message));
            } else if (response.status === -1) {
              reject(new Error("You may not be connected to the internet."));
            } else {
              console.error("Failed to make service call", response);
              reject(new Error("Failed to make service call."));
            }
          });
        }

        run();
      });

      return a;
    }

    function openBungieNetTab() {
      chrome.tabs.create({
        url: 'http://bungie.net',
        active: true
      });
    }
    /************************************************************************************************************************************/

    function getBnetCookies() {
      return $q(function(resolve, reject) {
        chrome.cookies.getAll({
          domain: '.bungie.net'
        }, getAllCallback);

        function getAllCallback(cookies) {
          if (_.size(cookies) > 0) {
            resolve(cookies);
          } else {
            reject(new Error('No cookies found.'));
          }
        }
      });
    }

    /************************************************************************************************************************************/<commit_msg>Restrict the cookies we look for.<commit_after>(function() {
  'use strict';

  angular.module('dimApp')
    .factory('dimBungieService', BungieService);

  BungieService.$inject = ['$rootScope', '$q', '$timeout', '$http', 'dimState', 'toaster'];

  function BungieService($rootScope, $q, $timeout, $http, dimState, toaster) {
    var apiKey = '<KEY>';
    var tokenPromise = null;
    var platformPromise = null;
    var membershipPromise = null;

    $rootScope.$on('dim-active-platform-updated', function() {
      tokenPromise = null;
      platformPromise = null;
      membershipPromise = null;
    });

    var service = {
      getPlatforms: getPlatforms,
      getCharacters: getCharacters,
      getStores: getStores,
      transfer: transfer,
      equip: equip,
      equipItems: equipItems,
      setItemState: setItemState,
      getXur: getXur,
      getVendors: getVendors
    };

    return service;

    function assignResultAndForward(dataset, attribute, result) {
      dataset[attribute] = result;

      return result;
    }

    function handleErrors(response) {
      if (response.status === 503) {
        return $q.reject(new Error("Bungie.net is down."));
      }
      if (response.status < 200 || response.status >= 400) {
        return $q.reject(new Error('Network error: ' + response.status));
      }

      var errorCode = response.data.ErrorCode;
      if (errorCode === 36) {
        return $q.reject(new Error('Bungie API throttling limit exceeded. Please wait a bit and then retry.'));
      } else if (errorCode === 99) {
        openBungieNetTab();
        return $q.reject(new Error('Please log into Bungie.net in order to use this extension.'));
      } else if (errorCode === 5) {
        return $q.reject(new Error('Bungie.net servers are down for maintenance.'));
      } else if (errorCode === 1618 &&
                 response.config.url.indexOf('/Account/') >= 0 &&
                 response.config.url.indexOf('/Character/') < 0) {
        return $q.reject(new Error('No Destiny account was found for this platform.'));
      } else if (errorCode > 1) {
        return $q.reject(new Error(response.data.Message));
      }

      return response;
    }

    function retryOnThrottled(request) {
      var a = $q(function(resolve, reject) {
        var retries = 4;

        function run() {
          $http(request).then(function success(response) {
            if (response.data.ErrorCode === 36) {
              retries = retries - 1;

              if (retries <= 0) {
                // debugger;
                resolve(response);
              } else {
                $timeout(run, Math.pow(2, 4 - retries) * 1000);
              }
            } else {
              resolve(response);
            }
          }, function failure(response) {
            // debugger;
            if (response.data) {
              reject(new Error(response.data.Message));
            } else if (response.status === -1) {
              reject(new Error("You may not be connected to the internet."));
            } else {
              console.error("Failed to make service call", response);
              reject(new Error("Failed to make service call."));
            }
          });
        }

        run();
      });

      return a;
    }

    function openBungieNetTab() {
      chrome.tabs.create({
        url: 'http://bungie.net',
        active: true
      });
    }
    /************************************************************************************************************************************/

    function getBnetCookies() {
      return $q(function(resolve, reject) {
        chrome.cookies.getAll({
          domain: 'www.bungie.net'
        }, getAllCallback);

        function getAllCallback(cookies) {
          if (_.size(cookies) > 0) {
            resolve(cookies);
          } else {
            reject(new Error('No cookies found.'));
          }
        }
      });
    }

    /************************************************************************************************************************************/
{'fraction_non_alphanumeric': 0.18723143032535297, 'fraction_numerical': 0.008348680171884592, 'mean_word_length': 2.143959861057507, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, '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': '4732658', 'n_tokens_mistral': 2285, 'n_tokens_neox': 2150, 'n_words': 527}