-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
useMutation onError handler is not fired if error policy is set to "all" #10973
Comments
+1 Heads up to others - onComplete does not adhere to the behavior described in the docs either. 🤕 As a potential workaround you can use update on place of onError and onComplete. First param is a proxy to the cache. Second param is the raw response with both data and errors. Unlike onError and onComplete, update will not run after the component scope variables are updated so you must use the response contents passed to the method. |
Hi @Imran99 👋🏻 I'm looking at the reproduction and don't see where the error is being thrown that would trigger @CH-PatrickWalmsley let me know more about what you're seeing, do you have something runnable to take a look at? We do have a suite of unit tests that validate callback behavior, though I admit that sometimes they don't behave according to folks' expectations and are considering changing our approach in an upcoming major version. Eager to hear from either/both of you on how to figure things out from here 🙏🏻 |
Apologies @bignimbus I think I may have had some unsaved changes in my fork. I've added the throw back in which reproduces the issue: https://codesandbox.io/s/thirsty-darkness-crw7f8?file=/src/index.jsx |
+1 I'm noticing that |
Ok thanks for that, I'll share this with the team and get some more context. From what I understand, not every Error in your application can/should be expected to be handled through Apollo Client. Network errors and spec-compliant GraphQL errors from the server will be reported, but not necessarily client-side runtime errors. I'd categorize your example, which throws a plain JavaScript error inside the resolver of the mutation type, as being a client-side runtime error. If such an error were thrown on the server it would either be caught and passed down in the Can you share a little more about what you're seeing in the application you're working on? Where is the error being thrown? |
Thanks @bignimbus. At the moment the error handling behaviour seems to be a bit inconsistent. If you set errorPolicy to
My scenario is similar to the one in the sample application. I have some unexpected error happening in the resolver that I want to handle with a generic oops message on a particular screen that makes the request. |
Is this a resolver on the server, a local resolver, or using a |
irl the resolver is on the server yup. The behaviour of onError is the same. |
Ok thanks 🙏🏻 are you able to paste the JSON returned from the server? Feel free to remove any sensitive data, I'm more curious to hear whether the response has an |
Ok i'll see if I can dig that up. Note I'm using apollo server on the server side and that is handling the error formatting. |
Sample error: [
{
"errors": [
{
"message": "Request failed with status code 400",
"locations": [
{
"line": 5,
"column": 9
}
],
"path": [
"orders",
"nodes",
0,
"fulfillmentOrders",
0,
"quotes"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"stacktrace": [
"AxiosError: Request failed with status code 400",
"...obfuscated"
]
}
}
],
"data": {
"orders": {
"nodes": [
{
"fulfillmentOrders": [
{
"quotes": null,
"__typename": "FulfillmentOrder"
}
],
"__typename": "Order"
}
],
"__typename": "OrderConnection"
}
}
}
] |
Thanks for this info, it's much appreciated and helps narrow things down. I'm going to see if I can reproduce this in the fork and will get back to you! |
Hmm, still not having luck with a reproduction. Here's an example that returns |
@bignimbus looks like you're using an |
Ah my mistake, thanks for catching that @jerelmiller |
Dealing with the same. |
This has been fixed in #11103 and will be released with 3.8.0 in the next couple weeks. Thanks for reporting this! |
Thanks @jerelmiller ! |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Issue Description
Intended Outcome
From the docs the onError policy is called unless the
errorPolicy
is set toignore
.Actual Outcome
useMutation onError handler is not called when an error occurs on the graphql server and the error policy is set to
all
.Versions
"@apollo/client": "^3.7.15"
Link to Reproduction
https://codesandbox.io/s/thirsty-darkness-crw7f8?file=/src/index.jsx
Reproduction Steps
The code sandbox link reproduces the issue.
The text was updated successfully, but these errors were encountered: