Extjs processes HTTP responses globally

I'm a little stuck with ajax / http exception handling: I'm trying to handle 401 exception globally in extjs and trying to use the following code to do this:

 Ext.Ajax.on('requestexception', function (conn, response, options) { if (response.status === 401) { log.console = '401 recieved'; } }); 

It works fine and processes 401 , BUT only when you explicitly do Ext.Ajax.request() . It does not handle ajax stores ... So the question is: can I handle ALL 401 http errors that came into my application? Thanks!

+4
source share
1 answer

You will need to perform error handling for any Ext classes that you use for Ajax connections. Some of these may include Ext.data.Connection , Ext.data.proxy.Ajax and Ext.form.action.Action .

For example, with Ext.data.proxy.Ajax you can override the class to add a listener to requestexception :

 Ext.define('MyApp.override.AjaxProxy', { override: 'Ext.data.proxy.Ajax', constructor: function(config) { this.callParent(config); this.on('requestexception', MyApp.utils.Utils.handle401Error); } }) 
+2
source

Source: https://habr.com/ru/post/1488704/


All Articles