So what I want to achieve is to have a check run before every sort of Ajax request is executed that will check if an access token is about to expire, then renew it and continue the request, if not just continue the request.

So I'm trying to override the request-method of Ext.data.Connection, but I'm having some issues getting this to work the way I want it to. I.e. if I try to call "callSuper" in a callback, it just complains about not finding the superclass. If I wrap the whole original function body within the callback, form.submit() stops working, complaining about the form not being connected etc.

Any ideas or input?

PHP Code:
Ext.define('app.overrides.data.Connection', {
  
override'Ext.data.Connection',

  
// Should not be in this class, but rather an util class, just putting it here as an example
  
checkToken: function (minValidity) {
    return new 
Ext.Promise(function (resolve) {
      var 
expiresAt JSON.parse(localStorage.getItem('expires_at')),
        
expiresIn expiresAt Date.now();

      if (
expiresIn <= minValidity) {
        
renewToken(function (accessToken) {
          
resolve(accessToken);
        });
      } else {
        
resolve();
      }
    });
  },


  
// Override to check and renew access token before a network request - if necessary
  
request: function (options) {
    var 
me this;

    
me.checkToken(30).then(function (accessToken) {
      if (
accessToken) {
        
Ext.Ajax.setDefaultHeaders({
          
'Authorization''Bearer ' accessToken
        
});
      }

      
// call the original method - but what is the proper way to do so, without breaking anything?
    
});
  }
});