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?
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();
}
}
});
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With