AngularJs routeProvider http status 403

前端 未结 1 532
囚心锁ツ
囚心锁ツ 2020-12-23 17:54

I\'m doing authentication and authorization in the server side.

In angularJs I\'m doing the routing using the routeProvider like this.

$routeProvider         


        
相关标签:
1条回答
  • 2020-12-23 18:17

    AngularJS Interceptors - updated to v1.4.2

    The interceptors are service factories that are registered with the $httpProvider by adding them to the $httpProvider.interceptors array. The factory is called and injected with dependencies (if specified) and returns the interceptor.

    To read more: $http angularjs Doc

    Section config (part of it)

    .config(function ($httpProvider) {
        $httpProvider.interceptors.push('responseObserver');
    })
    

    Response - observer factory

    403.html and 500.html are existing HTML files, nice styled with some help content for user.

    .factory('responseObserver', function responseObserver($q, $window) {
        return {
            'responseError': function(errorResponse) {
                switch (errorResponse.status) {
                case 403:
                    $window.location = './403.html';
                    break;
                case 500:
                    $window.location = './500.html';
                    break;
                }
                return $q.reject(errorResponse);
            }
        };
    });
    

    To extend knowledge about interceptors: http://djds4rce.wordpress.com/2013/08/13/understanding-angular-http-interceptors/

    0 讨论(0)
提交回复
热议问题