-
Notifications
You must be signed in to change notification settings - Fork 297
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
Use fetch instead of apiFetch. #9936
Merged
aaemnnosttv
merged 10 commits into
develop
from
infrastructure/9485-periodic-connection-check
Jan 6, 2025
Merged
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
14e9cba
Use fetch instead of apiFetch.
ankitrox a646fb4
Use URL to construct.
ankitrox de0575c
Remove unused fetchMock use.
aaemnnosttv 5c8adab
Merge branch 'develop' into infrastructure/9485-periodic-connection-c…
ankitrox 7e43cfb
Merge branch 'infrastructure/9485-periodic-connection-check' of githu…
ankitrox e89a846
Set offline only when error code is fetch_error.
ankitrox 64c2d6a
Add test for fetch_error scenario.
ankitrox d3e9cbf
Merge branch 'develop' into infrastructure/9485-periodic-connection-c…
aaemnnosttv f555373
Simplify internet connection check.
aaemnnosttv 3cded87
Merge branch 'develop' into infrastructure/9485-periodic-connection-c…
aaemnnosttv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
After some more thought here, I think this is not quite the right solution (criticizing my own IB here! 😄).
The fact that we're reaching for some internal api-fetch data here is a smell that we should be using that instead. The reason I suggested using
fetch
instead was to avoid the additional cases whereapi-fetch
throws, wherefetch
only throws when the request fails. Essentially we should be able to do the same usingapi-fetch
with an additional check in the throw block asapi-fetch
returns a specific error in this case. See https://github.com/WordPress/gutenberg/blob/d9b726b8451746703cc1b9680487e3726ab4a03f/packages/api-fetch/src/index.js#L130-L131In summary, we can keep most of what we had before, but adjusted to use an approach closer to the suggested one here in letting the try/catch determine the result. The difference in using
api-fetch
is that we need to set the online state conditionally depending on the error code if it throws. I.e. if it throws and the error code isfetch_error
, only then should we set it to be offline. Any other error would mean the request happened, which is all we are concerned about here, and can be ignored.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.
Thanks @aaemnnosttv , I've made the changes according to the suggestion.