Reputation: 53
I have a web-application in ExtJs. I need to do logout, when response status of Ajax request is 401. I use this code:
Ext.Ajax.on('requestexception', function(connection, response, options){
if (response){
if (response.status == 401 && myApp.auth.userInfo != null){
myApp.auth.logout();
}
}
});
It works, but when I have a few requests myApp.auth.logout(); calls several times and I can't to login again, after reloading page I can login. Is there any filters for requests or some method to make Ext.Ajax.on('requestexception') synchronous, that function myApp.auth.logout(); calls only one time?
Upvotes: 3
Views: 1902
Reputation: 4987
Try adding this. This makes sure the success and failure callbacks are not executed, your application should stop (perhaps the following requests hitting your override are due to the failure/callbacks being executed in cascade), then execute logout
Ext.Ajax.on('requestexception', function(connection, response, options){
if (response){
if (response.status == 401 && myApp.auth.userInfo != null){
delete options.failure;
delete options.callback;
myApp.auth.logout();
}
}
});
Upvotes: 2
Reputation: 74176
You can use single: true
so your handler will handle just the next firing of the event, and then remove itself.
Ext.Ajax.on('requestexception', function (connection, response, options) {
response && response.status == 401 && myApp.auth.userInfo != null && myApp.auth.logout();
}, null, {
single: true
});
(See documentation)
Upvotes: 1