1
|
define([
|
2
|
"dojo/aspect",
|
3
|
"dojo/topic",
|
4
|
"dojo/_base/xhr"
|
5
|
], function(aspect, topic, xhr){
|
6
|
|
7
|
var logoutInProgress = false;
|
8
|
var loginUrl = '/stabile/login';
|
9
|
if (location.pathname != '' || location.hash!='') loginUrl += "?back=" + location.pathname + location.hash;
|
10
|
|
11
|
aspect.around(dojo, "xhr", function(originalXhr){
|
12
|
return function(method, args){
|
13
|
var dfd = originalXhr(method, args);
|
14
|
var errHandler = function(error){
|
15
|
if(logoutInProgress){
|
16
|
return error;
|
17
|
}
|
18
|
if(error.status === 401 || error.status === 403){
|
19
|
logoutInProgress = true;
|
20
|
topic.publish("message", {
|
21
|
message: "Your session has timed out...",
|
22
|
duration: 2000,
|
23
|
type:"warning"
|
24
|
});
|
25
|
var to_login_page = function(){
|
26
|
window.location.href = loginUrl;
|
27
|
};
|
28
|
// show message for 2 sec
|
29
|
setTimeout(to_login_page, 2000);
|
30
|
};
|
31
|
return error;
|
32
|
};
|
33
|
var emptyHandler = function(){};
|
34
|
dfd.then(emptyHandler, errHandler);
|
35
|
return dfd;
|
36
|
};
|
37
|
});
|
38
|
});
|