Fix error handling for observer.next #910
Merged
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.
When
observer.next
is called inqueryListenerForObserver
based on the results of a given query and itself throws an error, the error handling logic surrounding it automatically casts that error into anApolloError
, even though it didn't originate withinapollo-client
.This is a big problem in
react-apollo
(see this issue).observer.next
calls the method that forces a rerender, and when child components throw an error they bubble up and wind up being handled by thecatch
statement inqueryListenerForObserver
, which turns it into anApolloError
, effectively swallowing the error.This PR rearranges the error handling logic in order to effectively capture errors that occur within
apollo-client
(such as mismatches in data being read from the store) and allows errors that occur outside ofapollo-client
(when thrown from withinobserver.next
) to propagate correctly.TODO:
If this PR is a new feature, reference an issue where a consensus about the design was reached (not necessary for small changes)Add your name and email to the AUTHORS file (optional)If this was a change that affects the external API, update the docs and post a link to the PR in the discussion