-
-
Notifications
You must be signed in to change notification settings - Fork 515
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
feat: convert errors into ApolloError #1225
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { ApolloError, isApolloError } from '@apollo/client' | ||
|
||
export function toApolloError (error: unknown): ApolloError { | ||
if (!(error instanceof Error)) { | ||
return new ApolloError({ | ||
networkError: Object.assign(new Error(), { originalError: error }), | ||
errorMessage: String(error), | ||
}) | ||
} | ||
|
||
if (isApolloError(error)) { | ||
return error | ||
} | ||
|
||
return new ApolloError({ networkError: error, errorMessage: error.message }) | ||
} |
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.
@backbone87 @Akryum
Is this change correct? I've tried the latest stable @apollo/client@3.3 and the next version 3.4.1.
Both of them don't have have
.error
set, they only have.errors
set.This means error is never going to trigger
onError
.Here is my query options
In this case I have a partial error, i.e. both data and errors are returned. The old behaviour is it triggers
onError
but it no longer triggersThere 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.
I have tested with @apollo/client@3.4.1
.error
is set whenerrorPolicy=none
and it is not set whenerrorPolicy=all
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.
I can see the relevant PRs to the error field
apollographql/apollo-client@513d733#diff-80ebcd3dc48e85c12b2c8484c5355662ab98ceea358660eb3af536c584f6fa44R22
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.
my assumption was that ApolloQueryResult.error contains an ApolloError instance that already wraps ApolloQueryResult.errors, seems like this is not the case... so we need to create the ApolloError for ApolloQueryResult.errors outselves.
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.
@backbone87 I have the similar assumption but I can't find anything in official clearly says should
onError
be triggered or not whenerrorPolicy=all
. Looks like this might be an unclear behaviour onapollo/client
itself.I can see different PRs, some assume
onError
should be triggered and some assume it should not.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.
in the end vue-apollo wraps all this stuff anyway, so it can define its behavior (yay more convolution :))