<commit_before>/* Help configure the state-base ui.router */
(function() {
  'use strict';

  angular.module('blocks.router')
    .provider('routerHelper', routerHelperProvider);

  /** @ngInject */
  function routerHelperProvider($locationProvider, $stateProvider, $urlRouterProvider, $injector) {
    /* jshint validthis:true */
    var config = {
      docTitle: undefined,
      resolveAlways: {}
    };

    var provider = {
      configure: configure,
      $get: RouterHelper
    };

    $locationProvider.html5Mode(true);

    return provider;

    function configure(cfg) {
      angular.extend(config, cfg);
    }

    /** @ngInject */
    function RouterHelper($location, $rootScope, $state, logger) {
      var handlingStateChangeError = false;
      var hasOtherwise = false;
      var stateCounts = {
        errors: 0,
        changes: 0
      };

      var service = {
        configureStates: configureStates,
        getStates: getStates,
        stateCounts: stateCounts
      };

      init();

      return service;

      function configureStates(states, otherwisePath) {
        angular.forEach(states, buildState);

        if (otherwisePath && !hasOtherwise) {
          hasOtherwise = true;
          $urlRouterProvider.otherwise(otherwisePath);
        }

        function buildState(stateConfig, state) {
          stateConfig.resolve = angular.extend(stateConfig.resolve || {}, config.resolveAlways);
          $stateProvider.state(state, stateConfig);
        }
      }

      function init() {
        // Route cancellation:
        // On routing error, go to the dashboard.
        // Provide an exit clause if it tries to do it twice.
        $rootScope.$on('$stateChangeError', handleRoutingErrors);
        $rootScope.$on('$stateChangeSuccess', updateTitle);
        // Hack in redirect to default children
        // Discussions: https://github.com/angular-ui/ui-router/issues/1235
        // https://github.com/angular-ui/ui-router/issues/27
        $rootScope.$on('$stateChangeStart', redirectTo);
      }

      function getStates() {
        return $state.get();
      }

      // Private

      function handleRoutingErrors(event, toState, toParams, fromState, fromParams, error) {
        var destination;
        var msg;

        if (handlingStateChangeError) {
          return;
        }
        stateCounts.errors++;
        handlingStateChangeError = true;
        destination = (toState && (toState.title ? __(toState.title) : (toState.name || toState.loadedTemplateUrl))) || 'unknown target';
        msg = 'Error routing to ' + destination + '. '
          + (error.data || '') + '. <br/>' + (error.statusText || '')
          + ': ' + (error.status || '');
        logger.warning(msg, [toState]);<commit_msg>Log the actual error on stateChangeError<commit_after>/* Help configure the state-base ui.router */
(function() {
  'use strict';

  angular.module('blocks.router')
    .provider('routerHelper', routerHelperProvider);

  /** @ngInject */
  function routerHelperProvider($locationProvider, $stateProvider, $urlRouterProvider, $injector) {
    /* jshint validthis:true */
    var config = {
      docTitle: undefined,
      resolveAlways: {}
    };

    var provider = {
      configure: configure,
      $get: RouterHelper
    };

    $locationProvider.html5Mode(true);

    return provider;

    function configure(cfg) {
      angular.extend(config, cfg);
    }

    /** @ngInject */
    function RouterHelper($location, $rootScope, $state, logger) {
      var handlingStateChangeError = false;
      var hasOtherwise = false;
      var stateCounts = {
        errors: 0,
        changes: 0
      };

      var service = {
        configureStates: configureStates,
        getStates: getStates,
        stateCounts: stateCounts
      };

      init();

      return service;

      function configureStates(states, otherwisePath) {
        angular.forEach(states, buildState);

        if (otherwisePath && !hasOtherwise) {
          hasOtherwise = true;
          $urlRouterProvider.otherwise(otherwisePath);
        }

        function buildState(stateConfig, state) {
          stateConfig.resolve = angular.extend(stateConfig.resolve || {}, config.resolveAlways);
          $stateProvider.state(state, stateConfig);
        }
      }

      function init() {
        // Route cancellation:
        // On routing error, go to the dashboard.
        // Provide an exit clause if it tries to do it twice.
        $rootScope.$on('$stateChangeError', handleRoutingErrors);
        $rootScope.$on('$stateChangeSuccess', updateTitle);
        // Hack in redirect to default children
        // Discussions: https://github.com/angular-ui/ui-router/issues/1235
        // https://github.com/angular-ui/ui-router/issues/27
        $rootScope.$on('$stateChangeStart', redirectTo);
      }

      function getStates() {
        return $state.get();
      }

      // Private

      function handleRoutingErrors(event, toState, toParams, fromState, fromParams, error) {
        var destination;
        var msg;

        if (handlingStateChangeError) {
          return;
        }
        stateCounts.errors++;
        handlingStateChangeError = true;
        destination = (toState && (toState.title ? __(toState.title) : (toState.name || toState.loadedTemplateUrl))) || 'unknown target';
        msg = 'Error routing to ' + destination + '. '
          + (error.data || '') + '. <br/>' + (error.statusText || '')
          + ': ' + (error.status || '');
        logger.warning(msg, [toState, error]);
{'fraction_non_alphanumeric': 0.12513503781058696, 'fraction_numerical': 0.0032409074540871445, 'mean_word_length': 2.389261744966443, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, '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': '7053058', 'n_tokens_mistral': 1550, 'n_tokens_neox': 1487, 'n_words': 333}