Ext.ajax operates as a singleton, allowing you to establish a universal handler for any request errors that may occur.
To properly handle cases where the user lacks authorization, your server-side code must return an HTTP 403 status or something similar. Add the following snippet somewhere in your code (only once):
Ext.Ajax.on('requestexception', function(conn, response, options) {
if (response.status == 403) {
Ext.MessageBox.alert('Authentication', 'You are not logged in.');
/* You can implement a login panel or other action here */
}
};
If a session timeout causes an AJAX request to fail, you can elegantly manage it within your codebase.
The options parameter includes all of the AJAX request’s settings. By displaying a login interface and reauthenticating the user, you can automatically resubmit the original AJAX request they had initiated. This seamless process should not disrupt any other existing code that relies on AJAX requests.