Skip to content

[Feature] Allow providing your own implementation of fetch - #160

Open
opepin wants to merge 3 commits into
SalesforceCommerceCloud:mainfrom
opepin:issue-159
Open

opepin wants to merge 3 commits into
SalesforceCommerceCloud:mainfrom
opepin:issue-159

Conversation

@opepin

@opepin opepin commented Jun 8, 2024

Copy link
Copy Markdown

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

@opepin
opepin requested a review from a team as a code owner June 8, 2024 18:35
@salesforce-cla

salesforce-cla Bot commented Jun 8, 2024

Copy link
Copy Markdown

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.

@joeluong-sfcc

Copy link
Copy Markdown
Contributor

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?

@opepin

opepin commented Jul 3, 2024

Copy link
Copy Markdown
Author

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

@opepin opepin changed the title Issue 159 [Feature] Allow providing your own implementation of fetch Aug 23, 2024
@opepin

opepin commented Aug 23, 2024

Copy link
Copy Markdown
Author

fixes #159

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants