我有簡單的API和授權點手柄角401個迴應
當我請求API,我收到了401如果令牌是無效的(令牌失去有效性過去五分鐘)。
我知道我可以攔截401例如與
app.factory("HttpErrorInterceptorModule", ["$q", "$rootScope", "$location",
function($q, $rootScope, $location) {
var success = function(response) {
// pass through
return response;
},
error = function(response) {
if(response.status === 401) {
// dostuff
}
return $q.reject(response);
};
return function(httpPromise) {
return httpPromise.then(success, error);
};
}
]).config(["$httpProvider",
function($httpProvider) {
$httpProvider.responseInterceptors.push("HttpErrorInterceptorModule");
}
]);
,但我想捕捉和排隊的請求並顯示一個登錄表單,如果是,則成功改變令牌(這是一個頭),並再次執行請求
請問您可以添加解釋嗎?以及如何排隊請求 – rkmax 2014-09-22 16:49:42
關於請求的隊列我會把它們放到緩存中,一些對象失敗請求,然後重定向,然後成功登錄後檢索。我會在15分鐘內解決答案。 – Artemis 2014-09-22 16:59:52
如果我在'request'函數中存儲'configs.push(config)'每個配置並在'response'函數'configs.pop()'中彈出,我如何識別每個響應屬於請求? – rkmax 2014-09-22 17:38:04