/java-script/

AngularJs interceptor error handling

2015-11-04 23:10:46

angular.module('myApp',[])

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

    .service('HttpInterceptor', ["$q", function ($q) {

        this.request = function (config) {
            return config;
        };

        this.responseError = function (response) {

            switch (response.status) {
                case 401:
                case 403:
                case 500:
                    console.log("Server Error: " + response.status);
                    break;
            }

            return $q.reject(response);
        };
    }])
;