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

Enhance error handling in network fetch functions #267

Merged
merged 3 commits into from
Aug 16, 2023

Conversation

SanjeevLakhwani
Copy link
Contributor

This PR improves the error handling logic in the _unpaginatedNetworkFetch and _paginatedNetworkFetch functions, which are used to make API requests. Previously, when the server returned an error status, these functions would simply throw the HTTP status code and text. Now, they first attempt to parse the server's response and extract an error message from it. This allows the application to display more specific error messages to the user, providing a better user experience and clearer debugging information.

This change assumes that the server includes error messages in the body of error responses. If an error message from the server is not available, the HTTP status code and text are used as a fallback.

Changes:

  • Update _unpaginatedNetworkFetch and _paginatedNetworkFetch functions to extract error messages from server responses.

Testing:

Please ensure that error handling still works as expected, both for errors where the server includes a message and for other errors. Please also ensure that other parts of the application that use these functions are still functioning correctly.

src/utils/actions.js Outdated Show resolved Hide resolved
src/utils/actions.js Outdated Show resolved Hide resolved
@SanjeevLakhwani SanjeevLakhwani requested review from davidlougheed and removed request for v-rocheleau July 10, 2023 02:37
src/utils/actions.js Outdated Show resolved Hide resolved
Copy link
Member

@davidlougheed davidlougheed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@SanjeevLakhwani SanjeevLakhwani merged commit c15c6e1 into master Aug 16, 2023
3 checks passed
@davidlougheed davidlougheed deleted the generic-api-error branch January 31, 2024 19:53
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.

3 participants