Multiple interceptors arcgis 4.x

1022
4
01-04-2022 06:02 AM
Dvirus
by
New Contributor III

Hi,

Arcgis 4.x JSAPI

esriConfig.request.interceptors support multiple interceptors?

 

0 Kudos
4 Replies
ReneRubalcava
Frequent Contributor

It takes an array of interceptors, each can intercept a different URL, so yes, it can.

https://developers.arcgis.com/javascript/latest/api-reference/esri-config.html#request

0 Kudos
Dvirus
by
New Contributor III

Hi,

This is also what I thought but unfortunately it does not work..

Here is an pen example.

https://codepen.io/Dvirus/pen/GRMdzLW?editors=1001

 

0 Kudos
ReneRubalcava
Frequent Contributor

You need to specify the "urls" string so the interceptor knows which URL should be intercepted. the way you have it set up the "urls" is null or undefined, so the first one overwrites the second.

Dvirus
by
New Contributor III

Thanks you! it's working! 

Apparently Arcgis Experience Builder already add interceptor at file

client\dist\jimu-arcgis\index.js (it's built minified)

 

(e=re.request.interceptors)||void 0===e||e.push({after:e=>{var t,i;(null===(t=null==e?void 0:e.url)||void 0===t?void 0:t.indexOf("/rest/info"))&&(null===(i=null==e?void 0:e.data)||void 0===i?void 0:i.owningSystemUrl)&&this.registOAuthInfo(e.data.owningSystemUrl)}}),

 

 but they add interceptor without urls property

so even if I add urls

 

 esriConfig.request.interceptors.push({
    urls: /FeatureServer\/\d+/,
    after: function (response) {     
      response.data.supportedQueryFormats = "JSON";
    }
  });

 

It's not intercept.

I tried to add urls to the first interceptor

 

 esriConfig.request.interceptors[0].urls = /.*?/

 

or

 

 esriConfig.request.interceptors[0].urls = /.*/

 

also  not working
But 
when tried 

 

  esriConfig.request.interceptors[0].urls = /blalba.*/

 

It's seems like if hit the first interceptor it's not continue to the second one.
Meanwhile I do

 

esriConfig.request.interceptors.push({
    urls: /FeatureServer\/\d+/,
    after: function (response) {     
      debugger;
      response.data.supportedQueryFormats = "JSON";
    }
  });
  
  esriConfig.request.interceptors.reverse();

 

Any suggestions?
0 Kudos