Enhance error handling in network fetch functions #267
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.
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:
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.