I am trying to implement an interceptor in my Experience Builder 1.8 custom widget. Upgrading to latest Experience builder custom install is not an option right now. I need to intercept a url request and get json as the response and NOT pbf. This will fix an error I have with EXB1.8 and Enterprise 11.4.
I have read and tried to implement an interceptor, but not able to get it to actually work? Where in the Experience builder client code would I place this interceptor (file?) and/or what am I missing here. Currently I am just putting this in my Widget.tsx file of my custom witdget and it never gets fired.
Where do I put this in client directory? Currently I have at
client/your-extenstions/widgets/CustomNavbar/src/runtime/widget.tsx
import esriConfig from '@arcgis/core/config.js';
const myInterceptor = {
before: function (params) {
// Modify the request here
console.log('Intercepted request:', params);
return params;
},
after: function (response) {
// Modify the response here
console.log('Intercepted response:', response);
return response;
},
error: function (error) {
// Handle errors here
console.log('Intercepted error:', error);
return Promise.reject(error);
}
};
esriConfig.request.interceptors.splice(0, 0, myInterceptor);