0
我在AngularJS中找到有關我的$ httpProvider的解決方案時遇到問題。 我有一個Accessservice,我處理響應從服務器錯誤,此服務可以處理401,404 .. HTTP錯誤,並重定向到一個頁面。
但我有一個具體的網址,我不會申請這個AccessService。我如何處理這個問題?
Config.js:
$httpProvider.interceptors.push('MyService');
MyServices:
angular.module('myapp').factory('MyService', function ($q, $location) {
return {
responseError: function (rejection) {
var code = rejection.status;
if (code === 401)
$location.url('/auth');
if (code === 403)
$location.url('/unauthorized');
return $q.reject(rejection);
}
};
});
在我的控制器
:
$scope.sendForm = function(){
CustomService.posting($scope.form).then(function(data){
if(data.status == 200){
// code when 200
// no problem here
}
if(data.status == 415)
// line of code
if(data.status == 401)
// line of code
});
};
有禁用此攔截特定控制器或http請求的方式。?
在此先感謝!
在AccessService中,檢查URL,如果它是特定的URL,則不執行任何操作。 –
如何?這一行$ httpProvider.interceptors.push('AccessService');在config.js中whriten是 – mesmed
正如我所說:**在AccessService **中。不在代碼中添加到攔截器。 –