[Feature] Allow providing your own implementation of fetch
Allow providing your own implementation of fetch by delaying caching from instanciation to first call.
Fetch can now be instrumented for performance monitoring/error or data capture. https://docs.logrocket.com/docs/troubleshooting-sessions#network-requests-are-missing-or-not-being-recorded
Thanks for the contribution! Unfortunately we can't verify the commit author(s): Olivier Pepin <o***@m***.com>. One possible solution is to add that email to your GitHub account. Alternatively you can change your commits to another email and force push the change. After getting your commits associated with your GitHub account, sign the Salesforce Inc. Contributor License Agreement and this Pull Request will be revalidated.
Hi @opepin, thanks for creating this PR. Would you be willing to provide some documentation/example on how you would pass in a custom implementation of a fetch call and adding a unit test?
I don't have a unit test, but the idea would be to override the window.fetch method :
const { fetch: originalFetch } = window;
window.fetch = async (...args) => { let [resource, config ] = args; console.log('request interceptor before') const response = await originalFetch(resource, config); console.log('request interceptor after') return response; };
before calling the api
fixes #159