私は角度のインターセプターを書こうとしています(私はイオン性です)。 目標は、タイムアウトの要求を傍受して(それらの状態が-1であると仮定して)、モーダルを表示し、接続が完了するまで再試行することです。 インターセプタが期待どおりに動作しているように見えますが、接続が復元されても何も起こりません。私はreturn $http(rejection.config);
を$timeout
の内部に持つのは間違いです。インターセプター:再試行でタイムアウトモーダル
services.config(['$httpProvider', function($httpProvider) {
$httpProvider.interceptors.push(function($injector, $q, $timeout) {
return {
// we use the incerceptor to assign a timeout property to every http request
request: function (config) {
config.timeout = 5000;
return config;
},
responseError: function(rejection) {
// We assume timeouts have status=-1
var $http = $injector.get("$http");
var $rootScope = $injector.get("$rootScope");
// duration defines how long the modal screen will be open (in seconds)
var duration = 5;
var showModalAndRetry = function(rejection) {
$timeout(angular.noop, 1000).then(function() {
$rootScope.$broadcast("app.somethingWentWrong");
$timeout(angular.noop, duration * 1000).then(function() {
$rootScope.$broadcast("app.closeSomethingWentWrong");
console.log("resending");
console.log(rejection);
return $http(rejection.config);
});
});
};
switch(rejection.status) {
case -1:
return showModalAndRetry(rejection);
}
return $q.reject(rejection);
}
}
});
}]);
感謝を。とった。 – NoIdeaHowToFixThis