0
我有一个拦截器:AngularJS AJAX状态代码错误处理
angular.module('mobileDashboardApp')
.factory('HTTPInterceptor', function ($rootScope, $q, HTTPErrors) {
return {
responseError: function (response) {
$rootScope.$broadcast({
500: HTTPErrors.serverError,
503: HTTPErrors.serviceError
}[response.status], response);
return $q.reject(response);
}
};
})
而且常量定义如下:
angular.module('mobileDashboardApp')
.constant('HTTPErrors', {
serverError: 'internal-server-error',
serviceError: 'service-error'
})
我如何运行$ rootScope $上做一个控制台。记录每当有500错误?
在我的配置我添加使用拦截器:
.config(function ($httpProvider, $routeProvider) {
$httpProvider.interceptors.push([
'$injector',
function ($injector) {
return $injector.get('HTTPInterceptor');
}
]);