-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add timeout to api client #1468
feat: add timeout to api client #1468
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Thanks for your contribution @JimTacobs! Currently you can already set timeout for specific requests like
Not saying we shouldn't expand it to global case as well, but the usecase would be very useful here :) |
Certainly! I can see a few advantages to having the timeout set as a default on the HTTP client itself. Consistency During Migration: Centralized Configuration: Alignment with ofetch Standards: I hope this makes sense and aligns with the vision for the client. I’d be happy to discuss or refine this further based on your feedback! |
I like this reasoning 🙌, let's make a tiny bit more out of it
what would you say on that? |
@patzick Yes, that would all make perfect sense to also include in this PR! I'll find some time this week to add these points! |
@patzick All your requests have been added to the PR. |
@shopware/api-client
@shopware/api-gen
@shopware-pwa/composables-next
@shopware-pwa/helpers-next
@shopware-pwa/nuxt3-module
@shopware-pwa/cms-base
commit: |
CodSpeed Performance ReportMerging #1468 will not alter performanceComparing Summary
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff! Thank you for your contribution 🙌
Description
Added a timeout param that can be passed when creating an API client. This timeout is passed directly into ofetch.create, leveraging its functionality in setting up a default timeout for every request made with the client.
Created three relevant test cases that show that the timeout property does what it's supposed to do.
Created another two tests to show that the timeout can be overwritten using fetchOptions
I have opted against expanding the onResponseError method with error handling specific for timeout errors, as I am confident the already available and in use errorInterceptor will be sufficient. If users do want more, they can simply hook into onResponseError and add their own custom implementation.
Added documentation to show:
As I wasn't sure whether you'd also want it on the admin API client, I've omitted it here.
Type of change
New feature (non-breaking change which adds functionality)
ToDo's
None
Additional context
None