Skip to content
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

fix: replace ofetch native fetch #147

Merged
merged 4 commits into from
Jan 14, 2025
Merged

Conversation

alvarosabu
Copy link
Contributor

  • Removed the ofetch dependency from multiple files and replaced it with a customFetch utility for better error handling and flexibility.
  • Updated API calls in login, pull languages, and user actions to use the new fetch method.
  • Introduced a new ResponseError interface for improved error management.
  • Added a getStoryblokUrl utility function to centralize URL construction based on region.
  • Enhanced error handling in API error management to accommodate the new FetchError class.

How to test this PR

Unit tests remained the same. They are all passing

Other information

- Removed the ofetch dependency from multiple files and replaced it with a customFetch utility for better error handling and flexibility.
- Updated API calls in login, pull languages, and user actions to use the new fetch method.
- Introduced a new ResponseError interface for improved error management.
- Added a getStoryblokUrl utility function to centralize URL construction based on region.
- Enhanced error handling in API error management to accommodate the new FetchError class.
@alvarosabu alvarosabu requested a review from edodusi January 10, 2025 11:16
@alvarosabu alvarosabu self-assigned this Jan 10, 2025
@alvarosabu alvarosabu added p3-significant [Priority] Moderate issues, major enhancements feature [Issue] New feature or request labels Jan 10, 2025
src/utils/fetch.ts Show resolved Hide resolved
src/utils/fetch.ts Outdated Show resolved Hide resolved
src/utils/fetch.ts Outdated Show resolved Hide resolved
src/utils/fetch.ts Outdated Show resolved Hide resolved
src/utils/fetch.ts Outdated Show resolved Hide resolved
- Updated `NetrcMachine` and `SessionState` interfaces to use `RegionCode` for improved type safety.
- Refactored login actions to handle optional chaining for better error handling.
- Enhanced API calls to utilize the new `customFetch` utility with improved type definitions.
- Added tests for `customFetch` to ensure robust error handling and response management.
@alvarosabu alvarosabu requested a review from edodusi January 14, 2025 07:51
@alvarosabu
Copy link
Contributor Author

Hi @edodusi I simplified the fetch method, there was some over-engineering there, I also added some unit tests to it and typing using generics

src/commands/user/index.ts Outdated Show resolved Hide resolved
@alvarosabu alvarosabu requested a review from edodusi January 14, 2025 12:10
@edodusi
Copy link
Contributor

edodusi commented Jan 14, 2025

@alvarosabu everything works now, just a little note: if I launch the test command (I'm correctly logged in) I get this:

 Test  Attempting a test...
 
Error

▲ error HTTP error! status: 404

Is this ok for this command? Or unrelated with this PR?

@alvarosabu
Copy link
Contributor Author

@alvarosabu everything works now, just a little note: if I launch the test command (I'm correctly logged in) I get this:

 Test  Attempting a test...
 
Error

▲ error HTTP error! status: 404

Is this ok for this command? Or unrelated with this PR?

You can safely ignore the test command everywhere. It gives you 404 because it's pointing to an unexisting space:

@alvarosabu alvarosabu merged commit bcbb136 into next Jan 14, 2025
3 checks passed
@edodusi edodusi deleted the bugfix/replace-ofetch-native-fetch branch January 14, 2025 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature [Issue] New feature or request p3-significant [Priority] Moderate issues, major enhancements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants