2016-11-16 5 views
0

私はアプリケーションのバックエンドにSpring Bootを使用しています。私はリダイレクトしようとしているときにユーザーがWebサイトを使用中に承認を失ったときやバックエンドは、クライアントに401コードを送信します。AngularJS - ユーザーが認証インジェクタを紛失した場合のリダイレクト:modulerrエラー

私は私の設定ファイルにインターセプターを使用

var app = angular.module('myApp', [ 
    'ngRoute', 'ngResource','ngDialog', 'tableSort', 'ngMaterial', 'ngMessages', 'timer', 'config' 

]).config(function ($routeProvider, $httpProvider) { 

    $routeProvider 
     .when('/', { 
      templateUrl: 'views/main.html', 
      controller: 'LoginCtrl' 
     }) 
     .when('/main', { 
      templateUrl: 'views/main.html', 
      controller: 'LoginCtrl' 
     }) 
     .when('/home', { 
      templateUrl: 'views/home.html', 
      controller: 'UserAccount' 
     }) 
     .when('/search', { 
      templateUrl: 'views/find_document.html', 
      controller: 'findDocument' 
     }) 
     .otherwise({redirectTo: '/'}); 

    $httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; 

    var interceptor = ['$rootScope', '$q', function(scope, $q) { 
     function success(response) { 
      return response; 
     } 

     function error(response) { 
      var status = response.status; 
      if (status == 401) { 
       window.location = "/nologin" 
       return; 
      } 
      return $q.reject(response); 
     } 
     return function(promise) { 
      return promise.then(success, error); 
     } 
    }]; 
    $httpProvider.responseInterceptors.push(interceptor); 
}); 

私はこのコードをしようとすると、私はエラーを取得し、コンソールログに

エラー:

angular.js:38 Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.5.8/$injector/modulerr?p0=myApp&p1=Error%3A%2…Flocalhost%3A8080%2Fbower_components%2Fangular%2Fangular.min.js%3A21%3A179)(…) 

どこに問題がありますか?

EDIT:あなたの問題を見つけ、複製しようとすると、URL

Failed to instantiate module myApp due to: 
TypeError: Cannot read property 'push' of undefined 
    at http://localhost:8080/js/App.js:115:39 
    at Object.invoke (http://localhost:8080/bower_components/angular/angular.min.js:41:456) 
    at d (http://localhost:8080/bower_components/angular/angular.min.js:39:418) 
    at http://localhost:8080/bower_components/angular/angular.min.js:40:19 
    at q (http://localhost:8080/bower_components/angular/angular.min.js:7:355) 
    at g (http://localhost:8080/bower_components/angular/angular.min.js:39:319) 
    at cb (http://localhost:8080/bower_components/angular/angular.min.js:43:336) 
    at c (http://localhost:8080/bower_components/angular/angular.min.js:20:390) 
    at Bc (http://localhost:8080/bower_components/angular/angular.min.js:21:179) 
    at fe (http://localhost:8080/bower_components/angular/angular.min.js:20:1 
+0

あなたはhtmlでこれらのすべての徴候を参照していますか? – Sajeetharan

+0

正確には何ですか?これは私のhtmlファイルですhttps://github.com/MarcinLenda/WzB/blob/master/src/main/resources/static/index.html – lukassz

+0

@Sajeetharan私はそれらのすべてを持っていると思います – lukassz

答えて

0

から

エラー・ログ、私はこの記事が指摘するようresponseInterceptorsは推奨されていることが判明:

Interceptor not working

コードをリファクタリングする必要があります。

希望します。

関連する問題